Using Schedule
by Derk Adams · in Torque Game Engine · 10/19/2004 (3:32 pm) · 17 replies
Greetings,
I have looked around and found many different ways to format the schedule command. Can someone please shed some light on the correct way to format the command? As you can see, I have tried many different ways. The first call works because I get "0 0 0" at the beginning which is correct when standing still. I just want to continue recalling the function.
function updateHudVelocity(%this) {
velocityHud.setText("Speed: " @ %this.getVelocity());
// %this.schedule( 250, updateHudVelocity(%this) );
// schedule( 250, updateHudVelocity(%this) );
// schedule( 250, 0, %this.updateHudVelocity(%this) );
// %this.schedule( 250, "updateHudVelocity", %this );
// schedule(250, %this, updateHudVelocity,%this)
}
Thanks.
Ok, I think the real isse is that I am trying to get a value from a server function through a function that is on the client.
So, the better question is, knowing the player id, how do I get the result from getVelocity() from the server?
I have looked around and found many different ways to format the schedule command. Can someone please shed some light on the correct way to format the command? As you can see, I have tried many different ways. The first call works because I get "0 0 0" at the beginning which is correct when standing still. I just want to continue recalling the function.
function updateHudVelocity(%this) {
velocityHud.setText("Speed: " @ %this.getVelocity());
// %this.schedule( 250, updateHudVelocity(%this) );
// schedule( 250, updateHudVelocity(%this) );
// schedule( 250, 0, %this.updateHudVelocity(%this) );
// %this.schedule( 250, "updateHudVelocity", %this );
// schedule(250, %this, updateHudVelocity,%this)
}
Thanks.
Ok, I think the real isse is that I am trying to get a value from a server function through a function that is on the client.
So, the better question is, knowing the player id, how do I get the result from getVelocity() from the server?
About the author
#2
Schedule(milliseconds, simgroup, functionname, [parameter1, param2 . . . ])
and
simgroup is used to assign the schedualing to a certain simgroup
I believe the correct usage is...
Schedule(millisecs, eventDependsOnThis, functionname, [arg1, arg2 . . . ])
So say you were hitting someone with an instant fireball spell using...
spellDamageEnemy(%enemy, %damType, %amount);
and you wanted to schedule it for 5 seconds, your method is to use...
%player.schedule = schedule(5000, 0, "spellDamageEnemy", %enemy, %damType, %amount);
And if the enemy was deleted you would cancel it using...
if(isEventPending(%player.schedule)){ cancel(%player.schedule); }
My understanding was you could do that all at once using....
schedule(5000, %enemy, "spellDamageEnemy", %enemy, %damType, %amount);
And if the %enemy was deleted before the 5 seconds was up, the schedule would not execute at all because it was dependant upon the %enemy to exist . A better example would be if you had a projectile that could completely traverse the distance of your map in 2 seconds and you built a delete function to schedule a delete for 3 seconds after firing, then you would have something like....
Normally this function would be asking for errors and console spam
because it lacks proper checks
function deleteBullet(%proj)
{
%proj.delete();
}
but scheduled in this fashion.......
%proj = newBullet(){}
fire(%proj);
schedule(3000, %proj, "deleteBullet", %proj);
if the projectile collides and deletes 1 second after firing, then 2 seconds later the
schedule will find that %proj has already been deleted and the schedule will self cancel. If you use....
schedule(3000, 0, "deleteBullet", %proj);
Then you are going to get console spam from the .delete() unless you manually cancel the schedule.
Here's some examples of proper builds based on normal methods for Derk...
If you had a Bot that you wanted to follow a path after a 10 second delay instead of constantly following it, then instead of using..
%bot.followPath(%bot.path, -1);
you would use....
%bot.schedule(10000, "followPath", %bot.path, -1);
This of course could be a self canceling schedule as well. If the bot is deleted before the 10 seconds is up then the schedule will self cancel. Because essentially the engine see's...
%bot.schedule(10000, "followPath", %bot.path, -1);
and
schedule(10000, %bot, "followPath", %bot.path, -1);
as the same thing, the only difference is how they execute when the schedule is completed.
If you wanted to set a dead players shapeName to blank 5 seconds after he dies instead of instantly, you change...
%player.setShapeName(""); // instant
to either
%player.schedule(5000, "setShapeName", "");
or use a manual function setup like
function ClearName(%player)
{
%player.setShapeName("");
// some stuff here
// more stuff here
}
schedule(5000, %player, "ClearName", %player);
10/27/2004 (10:08 pm)
@ Anthony - I could be wrong, but I think you made a mistake on the actual usage of the schedule. You said...Schedule(milliseconds, simgroup, functionname, [parameter1, param2 . . . ])
and
simgroup is used to assign the schedualing to a certain simgroup
I believe the correct usage is...
Schedule(millisecs, eventDependsOnThis, functionname, [arg1, arg2 . . . ])
So say you were hitting someone with an instant fireball spell using...
spellDamageEnemy(%enemy, %damType, %amount);
and you wanted to schedule it for 5 seconds, your method is to use...
%player.schedule = schedule(5000, 0, "spellDamageEnemy", %enemy, %damType, %amount);
And if the enemy was deleted you would cancel it using...
if(isEventPending(%player.schedule)){ cancel(%player.schedule); }
My understanding was you could do that all at once using....
schedule(5000, %enemy, "spellDamageEnemy", %enemy, %damType, %amount);
And if the %enemy was deleted before the 5 seconds was up, the schedule would not execute at all because it was dependant upon the %enemy to exist . A better example would be if you had a projectile that could completely traverse the distance of your map in 2 seconds and you built a delete function to schedule a delete for 3 seconds after firing, then you would have something like....
Normally this function would be asking for errors and console spam
because it lacks proper checks
function deleteBullet(%proj)
{
%proj.delete();
}
but scheduled in this fashion.......
%proj = newBullet(){}
fire(%proj);
schedule(3000, %proj, "deleteBullet", %proj);
if the projectile collides and deletes 1 second after firing, then 2 seconds later the
schedule will find that %proj has already been deleted and the schedule will self cancel. If you use....
schedule(3000, 0, "deleteBullet", %proj);
Then you are going to get console spam from the .delete() unless you manually cancel the schedule.
Here's some examples of proper builds based on normal methods for Derk...
If you had a Bot that you wanted to follow a path after a 10 second delay instead of constantly following it, then instead of using..
%bot.followPath(%bot.path, -1);
you would use....
%bot.schedule(10000, "followPath", %bot.path, -1);
This of course could be a self canceling schedule as well. If the bot is deleted before the 10 seconds is up then the schedule will self cancel. Because essentially the engine see's...
%bot.schedule(10000, "followPath", %bot.path, -1);
and
schedule(10000, %bot, "followPath", %bot.path, -1);
as the same thing, the only difference is how they execute when the schedule is completed.
If you wanted to set a dead players shapeName to blank 5 seconds after he dies instead of instantly, you change...
%player.setShapeName(""); // instant
to either
%player.schedule(5000, "setShapeName", "");
or use a manual function setup like
function ClearName(%player)
{
%player.setShapeName("");
// some stuff here
// more stuff here
}
schedule(5000, %player, "ClearName", %player);
#3
Thanks for the response. I already figured out to use it, but wasn't using %this. Since I was running it on the client side only, it was working. However, by assigning it to a variable, I will be able to stop it if the player dies.
Gonzo,
I tried using:
%this.HudSchedule = schedule( 250, updateHudVelocity, %this);
and
schedule( 250, %this, "updateHudSchedule", %this);
Both didn't work. I am wondering if this is a client-server issue. Since I am running it on the client, I have only been able to get it to work by including the 0. I wonder if using your schedule command is the format required for the server? I don't have a need for it yet, but I will give it a try when I need a server schedule.
Thanks.
P.S. The difference in command use on the client side versus the server side continues to be an issue. I can see why there is so much confusion in the forum.
10/28/2004 (10:24 am)
Anthony,Thanks for the response. I already figured out to use it, but wasn't using %this. Since I was running it on the client side only, it was working. However, by assigning it to a variable, I will be able to stop it if the player dies.
Gonzo,
I tried using:
%this.HudSchedule = schedule( 250, updateHudVelocity, %this);
and
schedule( 250, %this, "updateHudSchedule", %this);
Both didn't work. I am wondering if this is a client-server issue. Since I am running it on the client, I have only been able to get it to work by including the 0. I wonder if using your schedule command is the format required for the server? I don't have a need for it yet, but I will give it a try when I need a server schedule.
Thanks.
P.S. The difference in command use on the client side versus the server side continues to be an issue. I can see why there is so much confusion in the forum.
#4
function updateHudSchedule()
{
}
And
function Player::updateHudSchedule(%this)
{
}
Using the function you gave you need to pass something to the function to make it work anyway. "%this" does not just magically appear there because you placed it there. Typical function structure would look like this...
function myNewFunction()
{
// Do stuff
}
%foo = myNewFunction();
function Player::myNewFunction(%this)
{
}
%foo = %player.myNewFunction();
Hope that helps you some.
10/28/2004 (12:11 pm)
Derk, you got the object relations all wrong. There is a big difference between...function updateHudSchedule()
{
}
And
function Player::updateHudSchedule(%this)
{
}
Using the function you gave you need to pass something to the function to make it work anyway. "%this" does not just magically appear there because you placed it there. Typical function structure would look like this...
function myNewFunction()
{
// Do stuff
}
%foo = myNewFunction();
function Player::myNewFunction(%this)
{
}
%foo = %player.myNewFunction();
Hope that helps you some.
#5
Ok, time for some training :)
I understand the use of Player::FunctionName(%this) and the relationship with %player.FunctionName() and use them extensively on the server side of the scripting. My issue is on the client side. For example, all of the functions in /client/scripts/default.bind.cs appear to be independent of an object. How do I assign these functions to an object (or do I need to)?
I do most things on the client side because I'm making a single player game. I have also removed the requirement that the player has to be on the ground to jump. As an example of the client side issue, I am trying to put an altitude limit on the jump. So, when the player presses the jump key, it sets $mvTriggerCount2 = 1, and when they release it, $mvTriggerCount2 = 0. I then want to run a schedule that checks the altitude against a limit and if exceeded, then set trigger2 to 0, but I need to be able to cancel this schedule when the key is released. Now, the jump function only takes the key value, what framework is the schedule in to be able to call it independant of the jump function?
Thanks,
Derk
10/29/2004 (10:13 am)
Gonzo,Ok, time for some training :)
I understand the use of Player::FunctionName(%this) and the relationship with %player.FunctionName() and use them extensively on the server side of the scripting. My issue is on the client side. For example, all of the functions in /client/scripts/default.bind.cs appear to be independent of an object. How do I assign these functions to an object (or do I need to)?
I do most things on the client side because I'm making a single player game. I have also removed the requirement that the player has to be on the ground to jump. As an example of the client side issue, I am trying to put an altitude limit on the jump. So, when the player presses the jump key, it sets $mvTriggerCount2 = 1, and when they release it, $mvTriggerCount2 = 0. I then want to run a schedule that checks the altitude against a limit and if exceeded, then set trigger2 to 0, but I need to be able to cancel this schedule when the key is released. Now, the jump function only takes the key value, what framework is the schedule in to be able to call it independant of the jump function?
Thanks,
Derk
#6
10/29/2004 (2:04 pm)
I think what you are looking for is...if( My condition is met )
{
cancel($JumpSchedule);
$JumpSchedule = schedule( My New Event );
}
#7
Exactly, but that brings me to another question. In the client scripting, global variables make sense as they would only be available to the client. In the server scripting, I have used global variables to keep track of all the bot objects for processing. Now, since I am on a single system, the client and server globals are available to each other. I assume that if I was connecting to an outside server, the server globals would not be available to the client scripts and visa versa. Am I correct?
Thanks.
10/30/2004 (8:05 am)
Gonzo,Exactly, but that brings me to another question. In the client scripting, global variables make sense as they would only be available to the client. In the server scripting, I have used global variables to keep track of all the bot objects for processing. Now, since I am on a single system, the client and server globals are available to each other. I assume that if I was connecting to an outside server, the server globals would not be available to the client scripts and visa versa. Am I correct?
Thanks.
#8
10/30/2004 (9:18 am)
Yes, that is correct
#9
10/30/2004 (10:32 am)
Thanks Gonzo. I appreciate the assistance.
#10
11/11/2004 (6:15 am)
Thanks,it's great
#11
I want to schedule an event to check for some condition then cancel it from within.
This gets called one time and it schedules itself
function checkBot(%index)
{
if($Bot[%index].data == 1)
{
cancel(checkBot)
}
echo("checking bot");
schedule(4000,0,checkBot,%index)
}
I set the $Bot[%index].data = 1 and the event never cancels.
How could I cancel the event from within the event itself?
11/27/2004 (9:10 am)
And yet here is another one.I want to schedule an event to check for some condition then cancel it from within.
This gets called one time and it schedules itself
function checkBot(%index)
{
if($Bot[%index].data == 1)
{
cancel(checkBot)
}
echo("checking bot");
schedule(4000,0,checkBot,%index)
}
I set the $Bot[%index].data = 1 and the event never cancels.
How could I cancel the event from within the event itself?
#12
Maybe restructure your function to something like this?:
11/27/2004 (6:46 pm)
Simply don't reschedule it.Maybe restructure your function to something like this?:
function checkBot(%index)
{
echo("checking bot");
if($Bot[%index].data != 1)
{
schedule(4000,0,checkBot,%index);
}
}
#13
I would like to know how to cancel the event the proper way. I tried to do it this way.
%event = schedule(4000,0,checkBot,%index)
then cancel(%event) in the test but that won't work either.
11/27/2004 (7:29 pm)
Yes that would work but this is a one shot deal. Player enters a trigger to activate it so it can only get called one time and has to continue itself till some condition is met. I would like to know how to cancel the event the proper way. I tried to do it this way.
%event = schedule(4000,0,checkBot,%index)
then cancel(%event) in the test but that won't work either.
#14
I don't see your code in context, but you may be jumping in and out of function scope. If that is the case, then your local var would be 0 when it gets re-evaluated.
Based on the code you displayed, you are ALWAYS rescheduling. If you don't want it to, then restructure your code, or "return" after the cancel.
11/27/2004 (10:41 pm)
Use $event instead of %event.I don't see your code in context, but you may be jumping in and out of function scope. If that is the case, then your local var would be 0 when it gets re-evaluated.
Based on the code you displayed, you are ALWAYS rescheduling. If you don't want it to, then restructure your code, or "return" after the cancel.
#15
11/28/2004 (4:17 am)
Cameron seems return was the trick. I figured the cancel would prevent the schedule from being called again. Thanks....
#17
function checkBot(%index)
{
if($Bot[%index].data == 1)
{
cancel(%botcheck);
return;
}
%botcheck = schedule(4000,0,checkBot,%index);
}
11/28/2004 (7:11 am)
Ok here tizfunction checkBot(%index)
{
if($Bot[%index].data == 1)
{
cancel(%botcheck);
return;
}
%botcheck = schedule(4000,0,checkBot,%index);
}
Associate Anthony Rosenbaum
simgroup is used to assign the schedualing to a certain simgroup, I useully leave it as a zero, some other usefull thing are test to see if a schedual is ocurring and canceling the schedual so for instance
function updateHudVelocity(%this) { velocityHud.setText("Speed: " @ %this.getVelocity()); %this.HudSchedule = schedule( 250, 0, updateHudVelocity, %this); }Incase the player dies and things are schedualedfunction player::OnDisabled(%this, %obj) { if(isEventPending(%this.HudSchedule )) cancel(%this.HudSchedule); }