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

2019/6/17

Using a variable which is defined in actor in a world

FarbKlexx FarbKlexx

2019/6/17

#
I have kind of a counter in an actor and when it hits a ceirtain case, the variable which is defiened in the actor should = 1. When the Variable == 0 the world should delete the actor and create a different one. How can I ask in the World if the variable is == 0?
danpost danpost

2019/6/17

#
FarbKlexx wrote...
I have kind of a counter in an actor and when it hits a ceirtain case, the variable which is defiened in the actor should = 1. When the Variable == 0 the world should delete the actor and create a different one. How can I ask in the World if the variable is == 0?
Instead of asking, just tell the world when it hits zero. In actor:
if (counter > 0 && --counter == 0) ((MyWorld)getWorld()).doSomething();
In world, add a method:
public void doSomething()
{
    // do it herv
}
You need to login to post a reply.