Cancel(); ?
by Adam Troutman · in General Discussion · 08/17/2006 (3:45 pm) · 4 replies
I can't seem to get this event to cancel I have read some posts and things on it and I don't see what I am doing wrong so maybe someone could clear things up for me. here is the code involved:
function dying(%obj)
{
schedule(5000, 0, dying, %obj);
echo("you have cancer!");
%obj.applydamage(3);
}
$smokeschedule = schedule(5000, 0, dying, %obj);
function quitsmoking()
{
echo("stopped smoking*****");
cancel( $smokeSchedule );
return;
}
function packofcigsImage::onMount(%this,%obj,%user)
{
echo("cigs mounted");
%obj.applydamage(3);
schedule(5000, 0, dying, %obj);
%rightImage = %obj.getMountedImage($RightHandSlot);
if(%rightImage)
{
if(%rightImage.armready)
{
%obj.playthread(1, armreadyboth);
return;
}
}
%obj.playthread(1, armReadyLeft);
}
function packofcigsImage::onUnmount(%this,%obj)
{
echo("unmounted cigs");
quitsmoking();
%rightImage = %obj.getMountedImage($RightHandSlot);
if(%rightImage)
{
if(%rightImage.armready)
{
%obj.playthread(1, armreadyright);
return;
}
}
%obj.playthread(1, root);
}
#2
08/17/2006 (4:22 pm)
Also it is safe to do if( iseventPending($smokeschedule)) $smokeschedule.cancel(); just in case
#3
08/17/2006 (4:24 pm)
Orion's right. There's only one place in your code where $smokeSchedule is assigned, and that's for 1 occurence. Try this:function dying(%obj)
{
$smokeSchedule = schedule(5000, 0, dying, %obj);
echo("you have cancer!");
%obj.applydamage(3);
}
function quitsmoking()
{
echo("stopped smoking*****");
if(isEventPending($smokeSchedule))
{
cancel( $smokeSchedule );
}
return;
}
function packofcigsImage::onMount(%this,%obj,%user)
{
echo("cigs mounted");
%obj.applydamage(3);
$smokeSchedule = schedule(5000, 0, dying, %obj);
%rightImage = %obj.getMountedImage($RightHandSlot);
if(%rightImage)
{
if(%rightImage.armready)
{
%obj.playthread(1, armreadyboth);
return;
}
}
%obj.playthread(1, armReadyLeft);
}
#4
08/17/2006 (4:58 pm)
Thanks a lot you guys I see a few things that you guys have pointed out and it works now I learned some things, thanks.
Associate Orion Elenzil
Real Life Plus
right now you're only doing it for one of them.
also,
i advise canceling $smokeSchedule right before re-scheduling it.