Author Topic: Scheduling a variable declaration  (Read 988 times)

Is there an easier way to schedule a variable declaration than making a function for it?

Code: [Select]
schedule(500,0,eval,"$myVar = 7;");

Code: [Select]
schedule(500,0,eval,"$myVar = 7;");
Is there any danger involved with eval when doing this?

Unless you're inserting user input, then no.

Ok. And would setting a variable to an object go like this?
%client.schedule(500,eval,"myVar = 7;");

The 2nd parameter of SimObject::schedule is the name of the function on the SimObject, therefore GameConnection::eval is not a function.

I would instead do something like

%client.varschedule = schedule(500, 0, eval, "$myvar = 7;");

(btw you also forgot the $)

Then you can later you can do things like

if(iseventpending(%client.varschedule))
   cancel(%client.varschedule);

and I believe if the client is deleted, so is the schedule, but I could be mistaken.
Edit: actually probably not unless you do a schedule actually parented to the object with %client.schedule()

(btw you also forgot the $)
No he didn't, he wanted to set a variable to the object, not declare a global variable.

I would instead do something like

%client.varschedule = schedule(500, 0, eval, "$myvar = 7;");

(btw you also forgot the $)

Then you can later you can do things like

if(iseventpending(%client.varschedule))
   cancel(%client.varschedule);

and I believe if the client is deleted, so is the schedule, but I could be mistaken.
Edit: actually probably not unless you do a schedule actually parented to the object with %client.schedule()
That will do, thanks everyone
Edit: wait nope that won't do. Thanks @ below, greek, that's what I need
« Last Edit: June 28, 2012, 12:50:26 PM by Treynolds416 »

To set a variable on an object, do this:

Code: [Select]
%obj=clientgroup.getobject(0);
%value = 17;
schedule(500,0,eval,%obj @ ".variable =" SPC %value @ ";");

No he didn't, he wanted to set a variable to the object, not declare a global variable.

oh well silly me

if(iseventpending(%client.varschedule))
   cancel(%client.varschedule);
woah what

what does this do

woah what

what does this do
If it's scheduled but hasn't happened yet...

If it's scheduled but hasn't happened yet...
does it return the schedule?
what if there are mroe than one schedule?

wait no varSchedule is the schedule

ummm

umm

does it return the schedule?
what if there are mroe than one schedule?

wait no varSchedule is the schedule

ummm

umm
You can assign a schedule to a variable for later reference, for canceling it or checking on if it had already happened.