Game Development Community

Setting a variable with a schedule?

by Philip Mansfield · in Torque Game Builder · 01/07/2006 (3:00 pm) · 4 replies

Is this possible? I've tried a few different variations, but I basically want $levelData.hitSides to be changed to !$levelData.hitSides.

If I have to have a seperate function to do it, then so be it, but it seems a bit of overkill.

#1
01/07/2006 (3:18 pm)
I wrote this function a while ago(along with a number of other "helper" script methods):
//
// This sets %foo to %bar
// Usefull to schedul setting any global variable to %bar
// where the global variable is passed in as a string
function setGlobal(%foo, %bar) {
   eval(%foo@" = "@%bar@";");
}

Useage:
schedule(5000, 0, "setGlobal", "$MyGlobal", %someValue);

Notice that the global has to be passed in as a string. You can do this easily like so(tho I haven't tested this):

schedule(5000, 0, "setGlobal", "@$MyGlobal@", %someValue);
#2
01/07/2006 (4:21 pm)
$leveldata better be an object for that to ever work Phillip.

Ian
#3
01/07/2006 (4:38 pm)
Oh, right... I have a function for that, too. :)

//
// Set object member %foo of %obj to %bar
// Usefull for setting any scripted object member
function setObjectVar(%obj, %foo, %bar) {
   eval(%obj@"."@%foo@" = "@%bar@";");
}
#4
01/07/2006 (4:51 pm)
Well, I have a SimSet and each item in the simset represents a level. I wasn't sure of the best way to access that data throughout the various functions of my game so at the start of each level I simply do:
$levelData = GameLevelSet.getObject($levelNum);
It's probably not the best solution, but it works well enough at the moment.

Thanks for the code Josh, I'll plug it in the morning and see how it goes.