iterating through types as a function?

Blitz3D Forums/Blitz3D Programming/iterating through types as a function?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I would suggest using a Array of Types. I would also suggest using a integer for Id instead of a string for speed. Run the code below its very fast!

;truck object
Const TRUCK_MAX%=24
Type truck
	Field id%
	Field typeid% ;big=1, small=2, long=3, etc
	Field x#
End Type
Dim truckID.truck(TRUCK_MAX%) ;<-- truck Type Array

;New truck
Function truckCreate.truck(id%,typeid%,x#)
	this.truck=New truck
	this\id%=id%
	this\typeid%=typeid%
	this\x#=x#
	truckID.truck(this\id%)=this.truck ;<-- assign truck to array
	Return this
End Function

;create a dozen various trucks with random x#
For loop = 1 To 12
	truckType=Rnd(3)+1
	truckX#=Rnd(-100,100)
	truckCreate(loop,truckType,truckX#)
	Print "Truck #"+Str(loop)+", Type="+Str(truckType)+", X#="+Str(truckX#)
Next

;find truck
truck.truck=truckID(5)
x# = truck\x#
Print
Print "You Selected Truck #"+Str(truck\id%)+", Type="+Str(truck\typeid%)+", X#="+Str(truck\x#)
Print "X#="+Str(x#)

WaitKey()