Help with variables in Types

BlitzPlus Forums/BlitzPlus Beginners Area/Help with variables in Types

Mick Farrow(Posted 2008) [#1]
Hello, I am having trouble understanding how to have different variables for objects within a Type
& then checking for only 1 OBJ later.
e.g.

Type OBJ
Field X,Y
End Type
OBJNUM=5
For f=0 to OBJNUM
THIS.OBJ=New OBJ
THIS.OBJ\X=10:THIS.OBJ\Y=10 (How do I create 5 diff X/Y positions?)
Next

Any help much appreciated!


Beaker(Posted 2008) [#2]
You could do something like this:
Type OBJ
	Field X,Y
End Type

OBJNUM=5
For f=0 to OBJNUM
	THIS.OBJ=New OBJ
	THIS.OBJ\X = f*10
	THIS.OBJ\Y = f*5
Next


Not sure if this is all you were asking.


Mick Farrow(Posted 2008) [#3]
Thanks for reply Beaker,

basically, I want to have several objects at set positions(not random) around the screen & then check for collisions etc later,
i.e. don't want to check each object individually.


Sauer(Posted 2008) [#4]
What I would do is store your x and y variables in an array, then do something like this:

Dim coordinates(5,2)
coordinates(0,0)=10 ;an x coordinate
coordinates(0,1)=20 ;a y coordinate
coordinates(1,0)=223 ;another x coordinate
coordinates(1,1)=224 ;another y coordinate
;etc.  fill your entire array in this fashion...

Type OBJ
	Field X,Y
End Type

OBJNUM=5
For f=0 to OBJNUM
	THIS.OBJ=New OBJ
	THIS.OBJ\X = coordinates(f,0)
	THIS.OBJ\Y = coordinates(f,1)
Next




Mick Farrow(Posted 2008) [#5]
Thanks Sauer, that is just what I needed!