This site requires JavaScript, please enable it in your browser!
Greenfoot back
LakeOtis
LakeOtis wrote ...

2017/2/16

How to make a timer?

LakeOtis LakeOtis

2017/2/16

#
I want my character to have a reload time before using a move again, but I can't figure out, even with a lot of googling, how to get it to work. Currently there's a "Greenfoot.delay(5);" after the move, but it still doesn't work.
Nosson1459 Nosson1459

2017/2/16

#
Use an int variable which is increasing in the time that you want the timer to be stopping the move, when you want "a move" use an if for when that int is a certain number when it is "use a move" and reinitialize it.
int delay = 0;

delay++;
if (delay == 75)
{
    // things you want to do after delay
    delay = 0;
}
Show the class code that you want to have the timer in for further questions/explanation/assistance.
LakeOtis LakeOtis

2017/2/16

#
Nosson1459 wrote...
Use an int variable which is increasing in the time that you want the timer to be stopping the move, when you want "a move" use an if for when that int is a certain number when it is "use a move" and reinitialize it.
int delay = 0;

delay++;
if (delay == 75)
{
    // things you want to do after delay
    delay = 0;
}
Show the class code that you want to have the timer in for further questions/explanation/assistance.
How long will that delay for exactly? I'd want it to have a long-ish delay time, around 15 seconds.
danpost danpost

2017/2/16

#
LakeOtis wrote...
< Quote w/code Omitted > How long will that delay for exactly? I'd want it to have a long-ish delay time, around 15 seconds.
In a scenario running at normal speed (speed slider in the middle), a delay of 75 act cycles would be around one and one-third seconds. You would want a value more in the range of 800 to 900.
LakeOtis LakeOtis

2017/2/16

#
Thanks!
You need to login to post a reply.