Game Development Community

How to use schedule correctly?

by Bo Powell · in Torque Game Builder · 11/06/2008 (5:56 pm) · 2 replies

I have this function:

function HyperPickupBehavior::confirmPickup(%this, %targetObject, %inventoryItem)
{
if (!%targetObject.ActorBehavior)
return false;

if (%targetObject.ActorBehavior.isMethod("speedModifier"))
{
%targetObject.ActorBehavior.speedModifier(0.5); //This works perfectly.
schedule(4000, 0, "%targetObject.ActorBehavior.speedModifier(10)"); //This doesn't work at all.
}
return true;
}

All that matters is that this part: %targetObject.ActorBehavior.speedModifier(0.05); works perfectly...
and the schedule(4000, 0, "%targetObject.ActorBehavior.speedModifier(10)"); doesn't work at all.

I have tried MANY different combinations in there, as I've spent the last 2 hours trying to figure it out, needless to say, I'm pretty pissed right now.

It gives me an "Unknown Command" error when I use the schedule code like this:
schedule(4000, 0, "%targetObject.ActorBehavior.speedModifier(10)");

But If I take the quotes off, like so:
schedule(4000, 0, %targetObject.ActorBehavior.speedModifier(10));
I doesn't wait, it does the speed modifier instantly. Amazing!

Suggestions on what to put inside schedule? Thanks.

#1
11/06/2008 (6:17 pm)
Please read the info you have been linked to twice already.

The -very first- comment states:

"schedule(1000,0,bustAction,variableOne,variableTwo);

Just put variables after the function, and it should work. I haven't worked with it in a while, but the radar used to work like that before it was hard-coded."

Please, please just read a little. If you continue to have problems and can prove you have read (aka by not making mistakes clearly pointed out in the reading) I will help again.

Also please quit double posting.
#2
11/06/2008 (6:42 pm)
Based on order of operations, when you try to call the command:

schedule(4000, 0, %targetObject.ActorBehavior.speedModifier(10));

It processes the command %targetObject.ActorBehavior.speedModifier(10) (and hopes for a return value) before processing schedule.

To actually use the schedule command, you have two options:

%myObject.schedule(%timeDelayInMS, %functionName, %arg1, %arg2, ... , %argN);
 
// OR
 
schedule(%timeDelayInMS, %myObject, %functionName, %arg1, %arg2, ... , %argN);

In your case, you want to do this:

%targetObject.ActorBehavior.schedule(4000, "speedModifier", 10);

I suggest that you read up on specific functions in the documentation provided with TGB once you hit a wall like this.