Scripting question
by Alex (Stalker) Sakablukow · in Torque Game Engine · 06/28/2006 (7:02 am) · 10 replies
Have a question to advanced scripters here ;)
Have a small error, what i cant figuret out:
--------------------------------------------------------------------------------------------------------------------------------
if (Player@%p@Data.Level_@%l@_Played==false) { Player@%p@Data.Level_@%l@_Played=true; }
--------------------------------------------------------------------------------------------------------------------------------
%l and %p are integers;
the left part (if (..)) works, the left {...} not. Torsion shows a error...
But where is the difference?
Have a small error, what i cant figuret out:
--------------------------------------------------------------------------------------------------------------------------------
if (Player@%p@Data.Level_@%l@_Played==false) { Player@%p@Data.Level_@%l@_Played=true; }
--------------------------------------------------------------------------------------------------------------------------------
%l and %p are integers;
the left part (if (..)) works, the left {...} not. Torsion shows a error...
But where is the difference?
#2
Your whole syntax is incorrect, though. The first part might not throw a syntax error, but it won't work inengine either. I once tried to work around a few design issues with your approach, but learned that TorqueScript does not work that way.
If you can explain what you're trying to do then it'll be easier to tell you a better solution.
06/28/2006 (7:27 am)
I guess you're trying to build a variable name of some sort, up there..Your whole syntax is incorrect, though. The first part might not throw a syntax error, but it won't work inengine either. I once tried to work around a few design issues with your approach, but learned that TorqueScript does not work that way.
If you can explain what you're trying to do then it'll be easier to tell you a better solution.
#3
you have somewhere:
Player1Data.Name="Dummy";
and
$i=1;
you write in the console:
echo(Player@%i@Data.Name);
you get:
Dummy
PS: I try to create "arrays".. (or something like that) ;) torque script has no arrays as i know, the "array"-ressource hasnt worked well for me..
06/28/2006 (7:29 am)
But this will work:you have somewhere:
Player1Data.Name="Dummy";
and
$i=1;
you write in the console:
echo(Player@%i@Data.Name);
you get:
Dummy
PS: I try to create "arrays".. (or something like that) ;) torque script has no arrays as i know, the "array"-ressource hasnt worked well for me..
#4
I might be wrong though, so keep at it.
06/28/2006 (7:32 am)
Which is the point. It works in some areas but not everywhere. See my earlier post.I might be wrong though, so keep at it.
#5
But you cannot create field names on the fly. This is a syntax error:
To do that, you need to use eval:
By using eval you can create a line of code dynamically and execute it.
06/28/2006 (8:59 am)
You can build object names on the fly. This works:echo(Player@%i@Data.Name);
But you cannot create field names on the fly. This is a syntax error:
echo(Player0Data.Level@%i@Played);
To do that, you need to use eval:
eval("%result = Player0Data.Level" @ %i @ "Played;");
echo(%result);By using eval you can create a line of code dynamically and execute it.
#6
Where PlayerData is either a ScriptObject, ScriptGroup or SimSet used to store refrences to your player objects.
Player[%p] is an array element used to store the reference to each player information
LevelPLayed[%i] is an array element used to store the level played status for each Player.
06/28/2006 (9:23 am)
The correct way to do this is using the following:PlayerData.Player[%p].LevelPlayed[%i] == true
Where PlayerData is either a ScriptObject, ScriptGroup or SimSet used to store refrences to your player objects.
Player[%p] is an array element used to store the reference to each player information
LevelPLayed[%i] is an array element used to store the level played status for each Player.
#7
Im a c++ programmer, and work with torque-script only since short time.. It can be a simple syntax error ;)
I have tryed to create a array of players with a array of level-information, but it seems not work.
i have used something like that:
new SimObject(PlayerData[x] :DefaultPlayerData)
{
LevelData[y]=new SimObject( :DefaultLevelData);
...
};
somewhere i set then the values like this:
for (x=1;x<=SomeValue;x++)
{
for (y=1;y<=SomeOtherValue;y++)
{
PlayerData[x].LevelData[y].SomeWhat=AnyVariable;
}
}
but the "SomeWhat" seems not to be set to any value...
06/28/2006 (11:16 pm)
@Harold: lol, i know, but that isnt the problem ;)Im a c++ programmer, and work with torque-script only since short time.. It can be a simple syntax error ;)
I have tryed to create a array of players with a array of level-information, but it seems not work.
i have used something like that:
new SimObject(PlayerData[x] :DefaultPlayerData)
{
LevelData[y]=new SimObject( :DefaultLevelData);
...
};
somewhere i set then the values like this:
for (x=1;x<=SomeValue;x++)
{
for (y=1;y<=SomeOtherValue;y++)
{
PlayerData[x].LevelData[y].SomeWhat=AnyVariable;
}
}
but the "SomeWhat" seems not to be set to any value...
#8
new SimObject(blah)...
You are creating a SimObject named "blah" not a sim object stored in %blah or $blah. If you want to store the SimObject in an array, try this instead
$PlayerData[x] = new Simobject(PlayerData:DefaultPlayerData){...}
The problem is you're trying to stick array locations in where names are supposed to go.
06/29/2006 (12:35 am)
The error in that last bit of syntax is that you can't use the pointer to an array location as the name of the object. When you writenew SimObject(blah)...
You are creating a SimObject named "blah" not a sim object stored in %blah or $blah. If you want to store the SimObject in an array, try this instead
$PlayerData[x] = new Simobject(PlayerData:DefaultPlayerData){...}
The problem is you're trying to stick array locations in where names are supposed to go.
#9
$player[x]= new SimObject(PlayerX :DefaultPlayerData)
{
Level[y]= new SimObject( :DefaultLevelData) {};
}
And acces the data with:
player[x].Level[y].Variable
?
06/29/2006 (5:00 am)
Can i use something like this?:$player[x]= new SimObject(PlayerX :DefaultPlayerData)
{
Level[y]= new SimObject( :DefaultLevelData) {};
}
And acces the data with:
player[x].Level[y].Variable
?
#10
What exactly are you trying to accomplish? Does a single player object actually need to store unique per level data inside it? I would tend to take a different approach more like:
06/29/2006 (8:27 am)
Try it and see if it works.What exactly are you trying to accomplish? Does a single player object actually need to store unique per level data inside it? I would tend to take a different approach more like:
function constructPlayer()
{
%this = new SimObject(Player:DefaultPlayerData) // note he's purposefully not uniquely named
{
LevelData = new SimGroup();
}
%level = new SimObject(Level:DefaultLevelData) { ... } // can abstract to a constructLevel method
%this.LevelData.add(%level);
}
// later we want to access this data
function PlayerClass::setScore(%this, %levelNum, %score)
{
%level = %this.LevelData.getObject(%levelNum); // get a handle on the level
%level.setScore(%score); // call the level's set score method
}
Torque Owner Martin de Richelieu