How do I gain access to a public variable? My Hero class has:
How would i go about accessing this value from another class?
public int speed = 4;
public int speed = 4;
// from world class
Hero hero = null; // variable to hold the Hero object (if any)
// can only get first element from list if there is a first element, so
if (!getObjects(Hero.class).isEmpty())
{
hero = (Hero)getObjects(Hero.class).get(0); // setting the variable
}
if (hero != null) // was field set to a Hero object
{
int speedValue = hero.speed; // getting your 'speed' value
// code dealing with speed
}