Variable Naming
by Jumex · in Torque Game Builder · 09/13/2007 (11:23 am) · 6 replies
Function test()
{
for(%x = 1; %x <= $tfu; %x=%x +1)
{
$@"f"@%x = "f"@%x;
}
}
TFU = Total Friendly Units
Assuming there are 3 units on the field that have the name f1, f2, and f3. This loop should create 3 variables for me to use.
$f1 = f1
$f2 = f2
$f3 = f3
now ="f"@%x works I tested it. However when I try to apply the same concept to the variable I keep getting parse errors.
{
for(%x = 1; %x <= $tfu; %x=%x +1)
{
$@"f"@%x = "f"@%x;
}
}
TFU = Total Friendly Units
Assuming there are 3 units on the field that have the name f1, f2, and f3. This loop should create 3 variables for me to use.
$f1 = f1
$f2 = f2
$f3 = f3
now ="f"@%x works I tested it. However when I try to apply the same concept to the variable I keep getting parse errors.
About the author
#3
{
eval(%win@"="@"$"@"fx"@%z@".x;");
eval(%unit@"="$"@"f"@%z@");
if(%win > $selectstart.x && %win < $selectend.x)
{
selectunit(%unit);
}
grr stuck agian. Okay in this one I have 3 variable already created these variables hold the position of the 3 selected objects from before. The variables are $fx1, $fx2, $fx3. This loop is supposed to cylcle through each variable and first associate it X position with %win then run it through the if statment and if it passes it will send the appropriate variable ($f1, $f2, $f3) to the function select unit.
Once agian I am getting Parse Errors :/
09/13/2007 (12:49 pm)
For(%z = 1; %z <= $tfu; %z=%z +1){
eval(%win@"="@"$"@"fx"@%z@".x;");
eval(%unit@"="$"@"f"@%z@");
if(%win > $selectstart.x && %win < $selectend.x)
{
selectunit(%unit);
}
grr stuck agian. Okay in this one I have 3 variable already created these variables hold the position of the 3 selected objects from before. The variables are $fx1, $fx2, $fx3. This loop is supposed to cylcle through each variable and first associate it X position with %win then run it through the if statment and if it passes it will send the appropriate variable ($f1, $f2, $f3) to the function select unit.
Once agian I am getting Parse Errors :/
#4
The 'for' keyword should be lower case and you need brackets when doing compound logical statements. The %z++ instead of %z=%z+1 is optional, but more elegant.
Gabriel
09/13/2007 (1:03 pm)
Try[b]f[/b]or(%z = 1; %z <= $tfu; %z[b]++[/b])
{
eval(%win@"="@"$"@"fx"@%z@".x;");
eval(%unit@"="$"@"f"@%z@");
if([b]([/b]%win > $selectstart.x[b])[/b] && [b]([/b]%win < $selectend.x[b])[/b])
{
selectunit(%unit);
}
}The 'for' keyword should be lower case and you need brackets when doing compound logical statements. The %z++ instead of %z=%z+1 is optional, but more elegant.
Gabriel
#5
09/14/2007 (10:00 am)
You need a semi-colon in that second eval line.
#6
09/19/2007 (9:47 pm)
Eval is an invaluable tool for making some clever script... as well as for creating some ugly and hard to debug code if not careful =0
Torque Owner Gabriel Notman
Try:
For more info see:
tdn.garagegames.com/wiki/TorqueScript_Console_Functions_5#eval.28_script_.29
Gabriel