Page 1 of 1

question about sprites

Posted: Tue Jan 06, 2004 6:46 pm
by freewilli
When using the sprite commands, they need to be passed a unique number. why is this?? shouldnt the command return the identifier instead of having to do each one explicitly?

what if i want to create sprites on the fly? do i have to keep some kind of global counter for every sprite i make? if so, this seems extremly klunky.
im confused. :(

Posted: Tue Jan 06, 2004 10:24 pm
by Fred
This dynamic number will be available very soon, don't worry :)

Posted: Tue Jan 06, 2004 11:43 pm
by freewilli
Thank you!

:D

Posted: Wed Jan 07, 2004 11:40 am
by blueznl
i use a small procedure for this...

Code: Select all

Procedure.l x_nr()
  Global x_nr.l, x_nr_n.l
  ;
  ; *** generates a new unique number
  ;
  ; in:      none
  ; retval:  unused unique number
  ;
  ; pure sometimes uses 'numbers' to identify elements instead of windows handles
  ; these numbers are arbitrary and fully defined by the user, this can cause trouble
  ; when using multiple libraries or code from different people as they might be reusing
  ; these unique numbers, for this purpose, i've added a x_nr procedure that returns
  ; a new unique number on every call
  ;
  ; you decide yourself if you want to free them or not :-)
  ; i would suggest doing so if you don't 'recycle' them using x_freenr()... 
  ;
  If CountList(x_nr_list()) > 0         ; which means there's some stuff on the list
    x_nr = x_nr_list()                  ; then use that number
    DeleteElement(x_nr_list())          ; and take if from the list
  Else
    x_nr = x_nr_n
    x_nr_n = x_nr_n+1
  EndIf
  ProcedureReturn x_nr
EndProcedure

Procedure x_freenr(n.l)
  ;
  ; *** recycles unique numbers
  ;
  ; put this number into the 'free numbers' list so it can be reused by x_nr()
  ;
  AddElement(x_nr_list())
  x_nr_list()=n
  ;
EndProcedure

you'll have it with windows, file handles, memory blocks, and what not...