Cycling through alternate types

Blitz3D Forums/Blitz3D Programming/Cycling through alternate types

slenkar(Posted 2003) [#1]
I got this but I dont know how to cycle through 2 types at once - alternately-
[CODE]

red_p.red_car = first red_car
blue_p.blue_car=first blue_car

for k = 1 to 100
moveentity blue_p\car,0,0,1
moveentity red_p\car,0,0,1
red_p=after red_p
blue_p= after blue_p
next

[/CODE]
but it doesnt let you do it that way, the type identifyer has to be INSIDE the loop which makes it not work.
Is there a way out of this?


jfk EO-11110(Posted 2003) [#2]
maybe you better use only one car type that will hold a color field or something...
Well I am not a type expert, I try to avoid them whenever possible. The situation you have just described might be one reason why I use simple arrays instead.


skidracer(Posted 2003) [#3]
For the code above to work each type would have to have exactly 100 instances, this code should process both lists synchronously no matter how many items in each list:

red_p.red_car = First red_car
blue_p.blue_car=First blue_car

While red_p<>Null Or blue_p<>Null

	If blue_p<>Null
		MoveEntity blue_p\car,0,0,1
		blue_p= After blue_p
	EndIf

	If red_p<>Null
		MoveEntity red_p\car,0,0,1
		red_p=After red_p
	Next
Wend



slenkar(Posted 2003) [#4]
What does NULL mean?

1.equals zero
or
2.doesnt exist


soja(Posted 2003) [#5]
In terms of types, NULL means "doesn't exist" (really, the pointer is pointing to memory address 0)

Example: If I create three instances of a type, I'll end up with something like this:

NULL  <- Before First MyType
  |
Instance1.MyType  <- First MyType
  |
Instance2.MyType
  |
Instance3.MyType  <- Last MyType
  |
NULL  <- After Last MyType


So, you can check to see if you've iterated off the end of the list by checking for NULL.