Type Field holding handle? Array of handles?

Blitz3D Forums/Blitz3D Programming/Type Field holding handle? Array of handles?

bigfoot(Posted 2006) [#1]
Dear Community,

I am just beginning to program with B3D. My goal is to create a maze with 25 rooms. I have the composed the rooms of inside walls, outside walls, and floors in order to texturize these parts separately. I bound all these meshes to a pivot calles 'RoomTmpl' which serves as a room template. Since all rooms will look basically look alike, I wanted to create a Type array with fields specifying the coordinates (where to put the room in space) and other items defining the rooms. I thought a Type array would allow me to loop over it in a For-loop and is thus a efficient way to update the rooms.

Thus, I wanted to do something like the following:

Type RoomProps
Field Name
Field Wall ; this is for holding the handle
Field x#, y#, z#
EndType

Dim Room.RoomProps(25)

For i = 1 To 25
Room(i) = New RoomProps
Room(i)\Name = MyNames$(i)
Room(i)\Wall = CopyEntity(RoomTmpl)
Room(i)\x# = Xcoord#(i)
Room(i)\y# = 0
Room(i)\z# = Zcoord#(i)

PositionEntity Room(i)\Wall,Room(i)\x#,Room(i)\y#,Room(i)\z#
Next

However, when I checked for errors I got the error message "Expecting 'NEXT' statement" (or something like that). I guess I cannot simply assign an Entity to a field in a Type (I do not get any line number associated with
the error - is there way to turn this on in B3D?).

However, I also tried this:
...
Room(i)\wall = handle(CopyEntity(RoomTmpl))
...

but I got the same error message.

Now, is it actually possible to save handles in a Type field? Or should I rather create an array of handles, e.g. Dim RoomHdl(25)? And if that is possible, what type does this array have? Integer? Or is this just the wrong approach to begin with?

Thanks for your help!


(tu) sinu(Posted 2006) [#2]
You can assign an entity to a field in a type.
Check that your array is declared before calling the array type:
Dim Room.RoomProps(25) is before any calls to a room() = new roomprops

or replace the line:

Room(i)\Wall = CopyEntity(RoomTmpl)

with
Room(i)\Wall = 0

and see if you still get a problem


bigfoot(Posted 2006) [#3]
Thanks, sinu. With your reply I found out that the Entity assignment was not the problem in my code (that worked fine just as you said), but rather some problem with the coordinate assignment.

Thanks, again. BTW, do you know if there a way to have B3D tell me the line number when is stumbles on some error in the code?


(tu) sinu(Posted 2006) [#4]
Run blitz in debugmode, it usually jumps to the line which has caused a problem in the debugger.