Game Development Community


#1
03/06/2005 (2:23 pm)
Errr, I'm a bit lost here. TorqueScript supports arrays? :)
#2
03/06/2005 (2:29 pm)
Not really, but it does fake them!

When you have %myArray[0] for example in a script, TGEScript compiles that as myArray_0, and uses that as a variable name. IIRC, %myArray[2,3] will turn into %myArray_2_3, etc.

So Robert's question about ignoring out of bounds is really not a factor, since there isn't really an internal representation of an array like we would be used to in a structured language. You also cannot do something like %myArray[2] (on a 2-d "array" such as myArray[2,5]), and expect anything meaningful as a value--it would just check the scope to see if myArray[2] existed, or create it.

There are some neat tricks you can do with this, but there are also some functionality with arrays in a structured language that you aren't going to see.
#3
03/06/2005 (2:39 pm)
Ahha! I knew about the one-dimensional array, from TGE's inventory code, but had no idea that idea extended to multidimensional. Ya learn something new every day.

I haven't really found much use for such arrays yet, but hey, it's good to know we can at least fake it if we have to!
#4
03/07/2005 (2:14 am)
I use this kinda' stuff in the tile-editor for the brushes. Each brush is a 2D array, each being a tile-element that's a script-object and I use the dynamic-fields to store the info. Very cool to use although something screams in the back of my head when I use typeless custom structures.

- Melv.