Cancelling schedules
by Ian Omroth Hardingham · in Torque Game Engine · 09/14/2004 (6:45 am) · 8 replies
Hey everyone.
Recently, I've been using the following kind of code to cancel schedules:
The simple fact is that the "if IsObject" often returns false when $mySchedule is an active schedule. Removing that if, and cancelling in any case, fixes my problems.
I unfortunately don't have time right now to get down to the root of the problem, and I may well be in error using isObject for this at all, but I'd thought I'd bring it up in case anyone had any suggestions.
Ian
Recently, I've been using the following kind of code to cancel schedules:
if (isObject($mySchedule)) cancel($mySchedule);
The simple fact is that the "if IsObject" often returns false when $mySchedule is an active schedule. Removing that if, and cancelling in any case, fixes my problems.
I unfortunately don't have time right now to get down to the root of the problem, and I may well be in error using isObject for this at all, but I'd thought I'd bring it up in case anyone had any suggestions.
Ian
About the author
Designer and lead programmer on Frozen Synapse, Frozen Endzone, and Determinance. Co-owner of Mode 7 Games.
#2
if ($mySchedule) { cancel($mySchedule); }
09/14/2004 (12:33 pm)
Check it out, the best of BOTH worlds....if ($mySchedule) { cancel($mySchedule); }
#4
10/27/2004 (7:14 pm)
Better if(isEventPending($mySchedule)) cancel($mySchedule);
#5
That is NOT correct.
If you know you are going to cancel a schedule, then just cancel it like so...
Nothing else is needed. The proper way to use "isEventPending" is to find out if a
schedule exists when it will impact the outcome of another schedule or function.
IMPROPER USE OF "isEventPending":
PROPER USE OF "isEventPending":
10/29/2004 (2:34 pm)
Quote:
Better if(isEventPending($mySchedule)) cancel($mySchedule);
That is NOT correct.
If you know you are going to cancel a schedule, then just cancel it like so...
cancel($mySchedule);
Nothing else is needed. The proper way to use "isEventPending" is to find out if a
schedule exists when it will impact the outcome of another schedule or function.
IMPROPER USE OF "isEventPending":
if( My condition is met )
{
if(isEventPending($MySchedule)) { cancel($MySchedule); }
$MySchedule = schedule( NewEvent );
}
// - Which would be better as
if( My condition is met )
{
cancel($MySchedule);
$MySchedule = schedule( NewEvent );
} PROPER USE OF "isEventPending":
function AmIscheduledToDie()
{
if(isEventPending(%client.deathSchedule)) { return "Yep, you are dead meat"; }
return "Nope, you are fine for now";
}
#7
if ( A && (some hugely cpu intensive function call) ) will actually never call your hugely cpu intensive function call if A is FALSE, because once the full logic check is failed (when A is FALSE), there is no need to call the function.
Or in this case, why check to see if an event is pending (which takes some cpu cycles), when you KNOW that you are going to cancel it. I think Gonzo's point is why do a function call to check if the event is pending, when you are going to cancel it without even caring what is returned.
The thing is, I think Anthony is using the isEventPending call as a validation that $MySchedule is a valid object (which can then be removed)--a "safety valve" similar to old school pointer validation:
if (myPointer && myPointer->data == 10).
In other words, while yes, you can use isEventPending as a validation check, it's not what it's there for!
10/29/2004 (3:51 pm)
It's kind of like why logic checks are short-circuited:if ( A && (some hugely cpu intensive function call) ) will actually never call your hugely cpu intensive function call if A is FALSE, because once the full logic check is failed (when A is FALSE), there is no need to call the function.
Or in this case, why check to see if an event is pending (which takes some cpu cycles), when you KNOW that you are going to cancel it. I think Gonzo's point is why do a function call to check if the event is pending, when you are going to cancel it without even caring what is returned.
The thing is, I think Anthony is using the isEventPending call as a validation that $MySchedule is a valid object (which can then be removed)--a "safety valve" similar to old school pointer validation:
if (myPointer && myPointer->data == 10).
In other words, while yes, you can use isEventPending as a validation check, it's not what it's there for!
#8
There is no safety in this case. "ifEventPending" and "cancel" do almost the exact same thing, BOTH of them walk down the event list, both of them look for a matching event, if "isEventPending" finds the event, it returns true, "cancel" cancels the event. If "isEventPending" finds nothing it returns false, if "cancel" finds nothing, it returns false. Why waste the cycles on a useless check.
Wait till you guys finally get into "cancelPendingEvents()", lol, then your really going to be confused.
10/29/2004 (8:07 pm)
Quote:
The thing is, I think Anthony is using the isEventPending call as a validation that $MySchedule is a valid object (which can then be removed)--a "safety valve" similar to old school pointer validation:
There is no safety in this case. "ifEventPending" and "cancel" do almost the exact same thing, BOTH of them walk down the event list, both of them look for a matching event, if "isEventPending" finds the event, it returns true, "cancel" cancels the event. If "isEventPending" finds nothing it returns false, if "cancel" finds nothing, it returns false. Why waste the cycles on a useless check.
Wait till you guys finally get into "cancelPendingEvents()", lol, then your really going to be confused.
Associate Chris Haigler
Jester Dance