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

2011/7/14

How to make a delay

1
2
3
kiarocks kiarocks

2011/7/14

#
How do you make a delay to pause something?
mjrb4 mjrb4

2011/7/14

#
If you're talking about actors, the best way is probably to use the act cycles to pause something. You could have a "pause" field as an integer, set it to some value, say 100, and if it's above 0 decrement it on each iteration then not do anything else. If it's 0 then you continue. The initial value could obviously be anything, the larger it is the longer the pause.
kiarocks kiarocks

2011/7/14

#
ok, how do i do that?
davmac davmac

2011/7/14

#
Which part are you having trouble with?
kiarocks kiarocks

2011/7/14

#
every part!
GameCode GameCode

2011/7/14

#
I agree to mjrb. This would be the source code, I think:
1
2
3
4
5
6
7
8
9
10
11
12
public int pause = 100;
 
public void act()
{
    if(pause>0)
        pause--;
   if(pause == 0)
   {
        Method1();
        Method2();
    }
}
GameCode GameCode

2011/7/14

#
There's also a method 'delay(int time)' in the Greenfoot class. But I'm not sure how to use it.
kiarocks kiarocks

2011/7/14

#
makes no sense, im sorry.
GameCode GameCode

2011/7/14

#
What does not make sense?
mjrb4 mjrb4

2011/7/14

#
@kiarocks - You've got a conceptual example as well as an example in code which pretty much implements what I said earlier. What part do you need clarification on? If things are still totally unclear then you need to be a bit more specific - what type of pause are you trying to implement? Halting an actor for a while? Pausing the whole scenario for a while? Is there a particular scenario you can point us to to explain what you want to achieve?
kiarocks kiarocks

2011/7/14

#
Here, called Coke thing for now
kiarocks kiarocks

2011/7/14

#
need to pause between adding actor.
davmac davmac

2011/7/15

#
kiarocks, still not clear. Do you need to pause the whole scenario, or just stop one actor from doing something for a while? If you want to pause the whole scenario, you can use Greenfoot.delay() which takes an "int" parameter, so for example:
1
Greenfoot.delay(5);
... you could have found this for yourself by reading the documentation! It took me a little while to work out that when you said "Here, called Coke thing for now" you meant that you had uploaded a scenario. How about providing a link to the scenario in the discussion? In summary, if you need help, do as much of the work yourself as you can, read the documentation, try to make it easier for the people who are trying to help you, and try to explain your problem clearly.
kiarocks kiarocks

2011/7/15

#
im trying to make it so it pauses one actor. do you have the code yet?
danpost danpost

2011/7/15

#
It would be helpful to know what action ends that actors 'paused' state. If a specific action triggers the end of the pause, you would probably add a boolean variable for the object class; if it is just a time thing, adding an int variable would be the thing to do. In the first case (a boolean variable), false could mean not active and true could be active
1
private boolean isActive = true;
and in the beginning of your 'act' method for your object:
1
if (isActive = false) { return; }
Use the above if you want to create the object in the paused state; use 'false' if created in active state. You will need to check for the action or state required to 'pause' and to 'activate' the object, and adjust the value of 'isActive' as needed. In the other case (an int variable)
1
private int pauseCt = 100;
Use the above if you want to create the object in the paused state; use '0' if created in active state. If created in the active state, code to pause must be used somewhere (whether checking for a certain state, or some other action triggering the pause . The '100' can be adjusted lower (to shorten the pause) or higher (to lengthen the pause) to suit your needs. In the beginning of your 'act' method for the object, add the following
1
2
3
4
if (pauseCt != 0) {
    pauseCt--;
    return;
}
There are more replies on the next page.
1
2
3