Hi all, I've been having problems with accessing a boolean from another actor.
I followed a tutorial for accessing variables from another actor, I followed it and got no compile errors, but still it does not seem to work.
Here is my code and what I'm trying to accomplish:
The start of the class I'm trying to get the variables from ( called John ):
The code in my Main (world) class:
And finally the code in my Car class, I'm trying to get the boolean in John's class in this class:
Everything compiles, I get no errors when running, but I cant seem to "move" my car, because the boolean value never seems to be true (while it is true in John's class).
public class John extends Actor
{
public boolean inCar = false;public class Main extends World
{
private John johnVariables;
public Main()
{
super(150, 150, 5);
johnVariables = new John();
buildings();
addObject ( new John(), 75, 125);
addObject ( new House(), 115, 80);
addObject ( new House(), 115, 125);
addObject ( new Car(), 75, 50);
}
public John getVariables()
{
return johnVariables;
}public void drive()
{
corners();
Main mainWorld = (Main) getWorld();
John john = mainWorld.getVariables();
//John john = getOneIntersectingObject(John.class);
if (john.inCar)
{
if (Greenfoot.isKeyDown("right")) turn(5);
if (Greenfoot.isKeyDown("left")) turn(-5);
if (Greenfoot.isKeyDown("up")) move(1);
}
}
