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

2018/5/25

Method only for 20 seconds

grnft grnft

2018/5/25

#
How does the code looks like when I want to create a method which works only 20 seconds? After those 20 seconds, my actor should act like before. Thanks in advance!
danpost danpost

2018/5/25

#
// field
private int specialActionTimer;

// in act
specialAction();

// with method
private void specialAction()
{
    if (specialActionTimer > 0)
    {
        // perform special action
        specialActionTimer--;
    }
}
When the special action is to begin, run this one line of code:
specialActionTimer = 1200; // 20 sec * 60 acts/sec
grnft grnft

2018/5/26

#
Thanks for your help, it worked!!
You need to login to post a reply.