Energy recharge delay
by Supernova · in General Discussion · 04/22/2009 (3:40 pm) · 7 replies
Hi,
I'm going to be using the energy bar as a sheild, I'm just wondering if there is any build in functions to add a recharge delay like the one for your health bar.
I'm going to be using the energy bar as a sheild, I'm just wondering if there is any build in functions to add a recharge delay like the one for your health bar.
About the author
#2
pseudo code:
That's pseudocode, so you'll have to use the actual real commands for it to work, but that should get you started. If you need any more help, just holler.
04/22/2009 (7:57 pm)
Well, you can write one...pseudo code:
function Player::onSpawn(%this)
{
%this.setRechargeRate(1); // this is the command to set recharge rate, AFAIK
}
function Player::onDamage(%this)
{
if(%this.energyRechargeDelay) // this is our "schedule variable"
%this.energyRechargeDelay.cancel(); // cancel it every time we're damaged so it's reset
%this.setRechargeRate(0); // don't recharge anymore
%this.energyRechargeDelay = %this.schedule(5000 , setRechargeRate, 1); // recharge again in 5,000 ms... or 5 seconds
}That's pseudocode, so you'll have to use the actual real commands for it to work, but that should get you started. If you need any more help, just holler.
#3
04/22/2009 (9:23 pm)
Awesome! Thanks! I got it working.
#4
04/22/2009 (9:39 pm)
Ok well I thought I got it working. I just can't get the schedule to cancel. I've tried using cancel(%this.energyRechargeDelay) and i've tried %this.energyRechargeDelay.cancel(); Neither one seemes to be working.
#5
You probably should use echo statements to debug it. Like...
and just look at the console log to see if it makes sense or not...
04/22/2009 (9:48 pm)
hmmm... well, I know for a fact that cancel(scheduledThingy) works... I use that in my scripts.You probably should use echo statements to debug it. Like...
echo("%this = " @ %this); // make sure %this is what we want...
echo("%this.energyRechargeDelay = " @ %this.energyRechargeDelay); // make sure it's a valid schedule reference...
if(%this.energyRechargeDelay)
{
echo("Entered if statement!");
cancel(%this.energyRechargeDelay);
}
%this.setRechargeRate(0);
%this.energyRechargeDelay = %this.schedule(5000 , setRechargeRate, 1); // recharge again in 5,000 ms... or 5 seconds
echo("NEW %this.energyRechargeDelay = " @ %this.energyRechargeDelay); // check the new one...and just look at the console log to see if it makes sense or not...
#6
04/23/2009 (12:38 pm)
I got it working thanks! In my code its %obj not %this. I just forgot to change the one in the cancel. Thanks again!
#7
04/23/2009 (1:11 pm)
Cool, I'm glad it worked out for you.
Supernova