Arrays.
by Juan Cruz · in Torque Game Builder · 07/07/2008 (8:34 am) · 10 replies
Hello everyone,
I'm working on a map randomizer, but I need to pass (wich I know I can't) an array so I can create a new maps.
Now, knowing I can't use arrays per se, can someone enlighten me so I can figure out the best way to work with it. I have 2 possible solutions.
1.- can I create a multilayer tilemap via scripting? I think that would be the best solution, but I haven't found any good documentation or tutorial about it.
2.- can you reference a variable within a variable (like PHP, where $$var can be used to dinamically call another vairable. e.g. if $var = 'foo' then $$var is the same as $foo)
thanks in advanced.
I'm working on a map randomizer, but I need to pass (wich I know I can't) an array so I can create a new maps.
Now, knowing I can't use arrays per se, can someone enlighten me so I can figure out the best way to work with it. I have 2 possible solutions.
1.- can I create a multilayer tilemap via scripting? I think that would be the best solution, but I haven't found any good documentation or tutorial about it.
2.- can you reference a variable within a variable (like PHP, where $$var can be used to dinamically call another vairable. e.g. if $var = 'foo' then $$var is the same as $foo)
thanks in advanced.
#2
07/10/2008 (4:41 pm)
You can also use a vector, separate the values by newline characters, then use string functions to read each value as a record.
#3
1. It does not seem like you can create a TileMap from script, but you can add a new TileLayer to the GlobalTileMap. However the process of doing this is sortof a pain in the ass. If at all possible I would say have the layers already exist in your level and just set their tiles in the generation process.
2. I haven't used PHP but it looks like you are talking about some form of pointers. There are no pointers in torquescript, eg, one variable cannot point to another variable. The only sortof exception is SimObject(s), since they each have a unique Id and Torque knows how to automatically resolve the Id into the object itself.
You can also use simSet(s) as a sortof dynamic array by adding and removing scriptObjects and store your data as dynamic fields in the scriptObjects. There is a highscore saving/loading tutorial on TDN that uses this technique.
07/10/2008 (5:54 pm)
When you say "pass" an array, do you mean from server to client? Or do you mean between functions? A global string ( eg. $mapArray = "bla bla bla" ) could contain lots of data and would be accessible from anywhere ( Nikos suggestion ).1. It does not seem like you can create a TileMap from script, but you can add a new TileLayer to the GlobalTileMap. However the process of doing this is sortof a pain in the ass. If at all possible I would say have the layers already exist in your level and just set their tiles in the generation process.
2. I haven't used PHP but it looks like you are talking about some form of pointers. There are no pointers in torquescript, eg, one variable cannot point to another variable. The only sortof exception is SimObject(s), since they each have a unique Id and Torque knows how to automatically resolve the Id into the object itself.
You can also use simSet(s) as a sortof dynamic array by adding and removing scriptObjects and store your data as dynamic fields in the scriptObjects. There is a highscore saving/loading tutorial on TDN that uses this technique.
#4
eg. loop through each tile of the layer setting each tile to a random imageMap
I actually made a little ScriptArray class which behaves like a Vector would in C++ and it exposes some of the Vector methods to script like push_back, pop_back. It probably doesn't do anything the other ScriptArray resource doesn't, but if it sounds like something useful I can post it.
07/10/2008 (6:00 pm)
Actually, if you're random map is going to take the form of a tilelayer, you don't necessarily needs any other array for storing information other than the tilelayer itself.eg. loop through each tile of the layer setting each tile to a random imageMap
I actually made a little ScriptArray class which behaves like a Vector
#5
actually it sounds like it probably does.
the other one is incredibly bare-bones, the real code is all of almost 50 lines.
07/10/2008 (6:05 pm)
> it probably doesn't do anything the other ScriptArray resource doesn'tactually it sounds like it probably does.
the other one is incredibly bare-bones, the real code is all of almost 50 lines.
#6
07/14/2008 (9:36 am)
Thanks for the posts, I'm evaluating the possibilities now.
#7
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=15077
Yeah I realize theres already like 5 out there. But mine does erase, erase_fast, and find! '-)
07/15/2008 (5:56 pm)
I just posted a totally script based ScriptArray resource here:www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=15077
Yeah I realize theres already like 5 out there. But mine does erase, erase_fast, and find! '-)
#8
i updated my resource to include pointers to yours,
which definitely looks more full-featured.
07/15/2008 (6:05 pm)
Nice, James.i updated my resource to include pointers to yours,
which definitely looks more full-featured.
#10
I used it in my current project to write some TileLayer operations.
Which will go up on TDN.
07/21/2008 (12:45 pm)
Working on a TDN Post using Jame's TScriptArray.I used it in my current project to write some TileLayer operations.
Which will go up on TDN.
Associate Orion Elenzil
Real Life Plus
but there's a script resource which implements primitive but passable arrays here.