Dynamic variable creation
by Scott Jaworski · in Torque Game Builder · 08/26/2006 (10:39 am) · 2 replies
I have a map file that I'm trying to read in and load sprites dynamically off of. Maps can be as small as 4 x 3 or as big as 60 x 60. I saw something in the strategy tutorial about creating new objects on the fly, but I can't seem to get it to work. The manual code looks like this:
$map00 = new t2dStaticSprite() {
scenegraph = SceneWindow2D.getScenegraph();
imageMap = "tilesgroundImageMap";
class = "MapTile";
frame = "1";
size = "120 100";
position = "600 440";
layer= "30";
x = "0";
y = "0";
};The variables need to be based on the location on the map (ie map00, map01, map10, map11, etc), but I'm not going to know how many to create until I get the first couple of lines in from the file (number or players, height and width). I've also tried using an array, but I get syntax errors when I try to load that way.%file = new FileObject();
if(%file.openForRead("~/data/maps/test.map"))
{
%numplayers = %file.readLine();
%maxx = %file.readLine();
%maxy = %file.readLine();
echo("Number of Players" @ %numplayers);
echo("Max X" @ %maxx);
echo("Max Y" @ %maxy);
%line = %file.readLine();
for(%j = 0; %j < %maxy; %j++)
{
for(%i = 0; %i < %maxx; %i++)
{
%place = getWord(%line, %i);
%mapplace = new t2dStaticSprite() {
scenegraph = SceneWindow2D.getScenegraph();
imageMap = "tilesgroundImageMap";
class = "MapTile";
frame = "1";
size = "120 100";
position = "600 440";
layer= "30";
x = "0";
y = "0";
};
echo(%place @ "-");
$map[%i][%j] = %mapplace;
}
}
}
else
{
error("CANNOT OPEN FOR READ");
}
%file.close();So what am I doing wrong? I tried doing $map @ %i @ %j in place of the $map[%i][%j] but that didn't work either. Any thoughts or suggestions?
#2
08/28/2006 (3:12 pm)
I'm glad you figured out your problem :) I would've been able to answer it though was gone this weekend to the PAX conference. If you run into any issues feel free to post again.
Torque Owner Scott Jaworski