Game Development Community

Schedule function problems

by Koen Van Baelen · in Torque Game Builder · 06/30/2007 (12:31 pm) · 2 replies

Here's a piece of code that's supposed to install an upgrade on a player wich turns itself off after five seconds. I can't use setTimerOn for this because it's already used to set the rate of fire. The DisableUpgrade function is executed immediately, and not after five seconds, so the upgrades simply never work. What am I doing wrong?

function Player::InitUpgrade()
{
switch ($Level)
{
case 1: %Number = (getRandom(0,10000) % 3) + 1;
}
echo(%Number);
switch (%Number)
{
case 1: MessageDisplay.setText("Double Fire!");
case 2: MessageDisplay.setText("Rapid Fire!");
case 3: MessageDisplay.setText("Controls reversed!");
}
$PlayerShip.Upgrade = %Number;
$PlayerShip.schedule(5000,$PlayerShip.DisableUpgrade(),"");
}

function Player::DisableUpgrade()
{
$PlayerShip.Upgrade = 0;
MessageDisplay.setText("...");
}

#1
06/30/2007 (12:47 pm)
Change $PlayerShip.DisableUpgrade() to just DisableUpgrade.
Should work, the way you have it now will indeed call the function right away. (and input any returned value into the schedule command).
#2
06/30/2007 (1:06 pm)
Okay, it works now. Thanks a lot!