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.

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