question about sprites

Just starting out? Need help? Post your questions and find answers here.
freewilli
New User
New User
Posts: 6
Joined: Wed Nov 26, 2003 5:59 am

question about sprites

Post 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. :(
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

This dynamic number will be available very soon, don't worry :)
freewilli
New User
New User
Posts: 6
Joined: Wed Nov 26, 2003 5:59 am

Post by freewilli »

Thank you!

:D
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply