Game Development Community

Trouble with 'schedule'

by Tim Hamilton · in Torque Game Builder · 01/13/2011 (1:00 am) · 0 replies

Hello all,

First post here. I found Torque Game Builder (T2D?) a couple weeks ago, and have been playing around with the trial ever since. Definitely the most intuitive 2d engine I found. I've been working with the Behavior Shooter project, using it as a base for my own side-scrolling shooter. I've been working on coding some of my own behaviors, and overall things are going well, albeit slowly. However, I'm running into trouble with one of my behaviors.

What I'm trying to do is create an ability with two modes:

1. The 'click' mode is activated if the user presses and releases the button, and deactivated when the button is pressed-and-released again.

2. The 'hold' mode is activated if the user holds down on the button for a certain length of time, deactivating when the button is released.

The way my code is written is as follows:

When the key bound to the behavior is pressed/released, it calls a function called DetermineMode:

function BehaviorBubbleShield::DetermineMode(%this, %val)
{
if ($gFullBubbleActive == false && $gPartialBubbleActive == false)

//If neither mode of BubbleShield is active...
{
if(%val == true) //...and the activate button has been pressed...
{
$gCharging = schedule(%this.ChargeTime, %this.ActivateFullBubbleMode, %this);
//...prepare to call Full Bubble(Hold) Mode.
}

if (isEventPending($gCharging) && %val == false)
//If Full Bubble(Hold) mode has not activated, but button has been released...
{
cancel($gCharging); //...cancel Full Bubble activation...
%this.ActivatePartialBubbleMode(%this);
//...and call Partial Bubble(Click) Mode instead.
}
}

The first thing this function does is look to see if both modes are inactive.

If they are, it then looks to see if the button has been pressed.

If it has been pressed, it proceed to schedule the activation of the 'hold' mode, in anticipation of the player continuing to hold the button. This schdule is proxied into $gCharging so that the schedule persists even if the function is exited.

If the player releases the button before it's been held down long enough(%this.ChargeTime, a behavior field set to a default of 500), the scheduled 'hold' mode activation is canceled on the function's next run-through, and the 'click' mode is activated instead.

Unfortunately, the schedule function doesn't seem to be calling ActivateFullBubbleMode, or canceling itself if the button is quickly released. I'm sure the solution is painfully simple, but I just can't seem to figure it out. I hope this isn't too confusingly written; I think I'm trying to explain all this to myself as well.

Cheers,
Tim

About the author

Recent Threads