bb custom types basics


Attention! 👉Starting November 2024, BlitzCoder.org will now be BlitzBasic.org.

 

Tweet blitz3d blitzbasic code-archives
RemiD

to better understand how the commands first, last, after, before, handle, object, work with bb custom types :

;custom types basics by RemiD 20230907
;look at the debuglog to understand what is happening...
Graphics3D( 640, 480, 32, 2 )

;custom type list
Type Tthing
 Field name$
 Field mesh
End Type

;create some instances in the list
thi.Tthing = New Tthing : thi\name = "pomme" : thi\mesh = CreateSphere(8)
thi.Tthing = New Tthing : thi\name = "poire" : thi\mesh = CreateSphere(8)
thi.Tthing = New Tthing : thi\name = "peche" : thi\mesh = CreateSphere(8)
thi.Tthing = New Tthing : thi\name = "orange" : thi\mesh = CreateSphere(8)
thi.Tthing = New Tthing : thi\name = "banane" : thi\mesh = CreateCylinder(8)
thi.Tthing = New Tthing : thi\name = "kiwi" : thi\mesh = CreateSphere(8)

;loop trhought the list
DebugLog("")
For thi.Tthing = Each Tthing
 DebugLog(thi\name)
Next

;go to the first in the list
DebugLog("")
thi.Tthing = First Tthing 
DebugLog(thi\name)

;go to the last in the list
DebugLog("")
thi.Tthing = Last Tthing 
DebugLog(thi\name)

;browse the list from first to last
DebugLog("")
thi.Tthing = First Tthing 
Repeat
 ;If( KeyHit(57)=True )
  DebugLog(thi\name)
  thi.Tthing = After thi
 ;EndIf
Until( thi.Tthing = Null )

;browse the list from last to first
DebugLog("")
thi.Tthing = Last Tthing 
Repeat
 ;If( KeyHit(57)=True )
  DebugLog(thi\name)
  thi.Tthing = Before thi
 ;EndIf
Until( thi.Tthing = Null )

;delete an instance in the list
c% = Rand(1,6)
count% = 0
For thi.Tthing = Each Tthing
 count = count + 1
 If( count = c )
  Delete( thi ) ;delete this instance
  DebugLog( thi\name ) ;'object does not exist' 
 EndIf
Next

;get the handle of each instance and put it in the entityname of each mesh
For thi.Tthing = Each Tthing
 NameEntity( thi\mesh, Handle(thi) )
Next

;get the handle in the entityname of a mesh (after a collision or after a linepick), an to retrieve the instance in the list
pickedEnt% = LinePick( sc, sy, sz, vx, vy, vz, radius )
thiH% = EntityName( pickedEnt )
thi.Tthing = Object.Tthing( thiH )
EntityColor( thi\mesh, 000, 000, 250 )

WaitKey()

End()

Reply To Topic (minimum 10 characters)

Please log in to reply