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

2016/10/28

I need to get variables from MyWorld into an actor

Shadow7 Shadow7

2016/10/28

#
so i have a few variables that are int the world class as private doubles. I am completely brain dead on how to use the variables from the world to the actor
danpost danpost

2016/10/28

#
Add public 'getter' methods to return each value:
// with a double field of
private double doubleValue;

// create this getter method
public double getDoubleValue()
{
    return doubleValue;
}
Then in actor class act method or method called from the act method:
double doubleValue = ((MyWorld)getWorld()).getDoubleValue();
will get the value.
Shadow7 Shadow7

2016/10/28

#
thank you, this works but then it produces a java.nullexperiance when I try add an actor to the world
danpost danpost

2016/10/28

#
Shadow7 wrote...
thank you, this works but then it produces a java.nullexperiance when I try add an actor to the world
The code supplied cannot throw that exception, unless you misplaced the last line of code given (it should be in act method or method called by the act method).
You need to login to post a reply.