Script Objects on Mission Change
by Xavier "eXoDuS" Amado · in Torque Game Engine · 03/28/2003 (7:05 pm) · 6 replies
I have a question here. Suppose you store a variable in the GameConnection object... in scripts. For example:
Now the question is, why this other thing doesnt work:
Thanks.
%client.myvar = "hello";And you now change missions, and when the new mission is loaded you try to echo that value, it will perfectly work. Same with global variables, etc.
Now the question is, why this other thing doesnt work:
%client.myobj = new ScriptObject() {
myvar = "hello";
};In this last case, when you load the mission and try to echo the values inside the scriptobject, the scriptobject doesnt exists. I'm guessin the scriptObject is deleted when the mission is destroyed, but is there any way to prevent this?Thanks.
About the author
#2
03/28/2003 (10:07 pm)
Yes Ron, I believe ScriptObjects automatically get added to the MissionCleanup group, not sure though.
#3
I think that will prevent the object from cleaning up.
If that dosnt work you can save it out to a file.
eg.
%client.myobj.save("fps/server/scripts/bla_backup.cs");
Then re-exec it on mission load.
03/30/2003 (1:58 pm)
If you dont want it destroyed just do something like this$Bla = new ScriptObject()
{
myvar = "hello";
};
%client.myobj = $Bla;I think that will prevent the object from cleaning up.
If that dosnt work you can save it out to a file.
eg.
%client.myobj.save("fps/server/scripts/bla_backup.cs");
Then re-exec it on mission load.
#4
Like:
03/31/2003 (4:52 pm)
I "think" that doing it that way has the same effect... the only difference is that you store it in a global var first. But if the script object is destroyed on mission end... guess it will be destroyed anyway. What I did was to store on a global var the script object and load it after new mission is loaded.Like:
$var = %cl.myObject; endGame(); missionLoad(blah); %cl.myObject = $var;That solved my problems for now, that save things comes in handy for other things though. Basically that's all I need to make a savegame for my game, since it's all text data :P
#5
03/31/2003 (5:17 pm)
Every object, upon creation, is added to a group called the "Instant Group". You can set which group this is by changing the $instantGroup variable. If you look in common/server/missionLoad.cs you'll see how the group is changed from the ServerGroup to the MissionCleanup group. A solution to this problem would be to add your dynamically created object to the client object like this:%client.myobj = new ScriptObject(); %client.add(%client.myobj);
#6
03/31/2003 (8:21 pm)
Interesting, I will have to remember that Mark. :)
Associate Ron Yacketta
-Ron