Schedule and Variables...?
by Cinder Games · in Torque Game Engine · 10/20/2005 (4:32 pm) · 8 replies
Can schedule be used to change variables.. or only call functions?
#2
came up with this idea.. but it's a total bust for what i want to do..... say...
$player.name = "Tim";
say i have this.. and want to change it to something else I'd like do envoke it like such.
ChangeVar($player.name,"John");
basically i'd like a universal variable changer, instead of having to do $player.name = newVariable
even doing
$cat="meow"
ChangeVar($cat, "woof");
doesn't change $cat's value.
any clues?
10/20/2005 (8:34 pm)
Hmmmm can't figure out how to get a function to change variables to work...function ChangeVar(%var1, %Var2){
%var1 = %var2;
}came up with this idea.. but it's a total bust for what i want to do..... say...
$player.name = "Tim";
say i have this.. and want to change it to something else I'd like do envoke it like such.
ChangeVar($player.name,"John");
basically i'd like a universal variable changer, instead of having to do $player.name = newVariable
even doing
$cat="meow"
ChangeVar($cat, "woof");
doesn't change $cat's value.
any clues?
#4
10/20/2005 (10:06 pm)
If I'm reading that right, the function code you show above only changes the local function's copies of the variables you're passing it. Nothing happens to the original (global) variables.
#5
10/20/2005 (10:19 pm)
Thanks Matthew! that's exactly what i was looking for... eval huh? i never knew that one existed!
#6
Doesn't actually accomplish anything is because you are passing parameters by copy, not by reference. In other words, even though within your code block %var1 does in fact be set to %var2, it doesn't communicate that information outside of the function, since they are both local variables which are created each time your function is called, and destroyed each time the function exits. Note that %var1 and %var2 are destroyed, not any objects that %var1 or %var2 might represent.
There are a couple of different ways to accomplish that however--either by using global variables (with a $ instead of a %), returning a value out of the function (return %var1, and calling the script on the right side of an = sign), or by calling accessor methods on your object (which you would also have to write), such as %var1.setVar(%var2);
10/21/2005 (5:41 am)
BTW, for Ramen and follow-on readers: the reason that this code:function ChangeVar(%var1, %Var2)
{
%var1 = %var2;
}Doesn't actually accomplish anything is because you are passing parameters by copy, not by reference. In other words, even though within your code block %var1 does in fact be set to %var2, it doesn't communicate that information outside of the function, since they are both local variables which are created each time your function is called, and destroyed each time the function exits. Note that %var1 and %var2 are destroyed, not any objects that %var1 or %var2 might represent.
There are a couple of different ways to accomplish that however--either by using global variables (with a $ instead of a %), returning a value out of the function (return %var1, and calling the script on the right side of an = sign), or by calling accessor methods on your object (which you would also have to write), such as %var1.setVar(%var2);
#7
Take a look at http://www.garagegames.com/mg/forums/result.thread.php?qt=25305
10/21/2005 (6:36 am)
I wrote a post that changes the engine to allow by reference variable passing.Take a look at http://www.garagegames.com/mg/forums/result.thread.php?qt=25305
#8
10/21/2005 (8:24 am)
Interesting. i'll have to see how that all works.
Torque 3D Owner Jacob