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

2017/3/17

Detect if running

101929ha 101929ha

2017/3/17

#
I would like some help with detecting if the script is running. I have currently got
1
2
3
4
if (started() == true)
{
 
}
but that says ''void' type not allowed here.' and if I say
1
2
3
4
if (started == true)
{
 
}
It says 'cannot find symbol - variable started' Please help and thanks in advance.
Super_Hippo Super_Hippo

2017/3/17

#
What script do you mean? If you want to detect if the scenario is running (=not paused), you don't need a condition at all because it is only executed when the scenario is running.
101929ha 101929ha

2017/3/20

#
I am using SimpleTimer and I would like to reset the timer, not when the world is created, but when the world is running (and also only update when the world is running).
Super_Hippo Super_Hippo

2017/3/20

#
You can't do that with the SimpleTimer class. The SimpleTimer class uses real time, so if you pause the scenario, the timer is still 'running'. I think it would be better to count act cycles. Example:
1
2
3
4
5
6
7
8
9
10
11
private int timer = 0;
 
public void act()
{
    timer++;
    if (timer == 100)
    {
        //do something
        timer = 0;
    }
}
101929ha 101929ha

2017/3/21

#
OK. Thanks for the help.
You need to login to post a reply.