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

2013/1/13

checking whether a method gets called

bonana bonana

2013/1/13

#
Hey everybody, I want my actor to do something if the world calls a method. I tried to do it like this:
World1 world = (World1) getWorld();
        if (world.method())
        {
               doSomething();
        }
but it says "incompatible types", pointing at the method-brackets.
Game/maniac Game/maniac

2013/1/13

#
In the world type this:
boolean methodCalled = false;

public void method()
{
    methodCalled = true;
}
then in your actor type this:
World1 world = (World1) getWorld();

if (world.methodCalled == true)  
{  
       doSomething();
}
bonana bonana

2013/1/14

#
Thank you!
You need to login to post a reply.