So basically, I have a class which I'll call ClassA. I then have ClassB which is a child class of ClassA.
ClassA has a variable called question. At the top of the document, it's defined as...
So in my World class, I add an object of ClassA. This works fine, and the setImage is random based on this variable.
Although, when I attempt to access the variable question from ClassB (the child class), it's defined as 0.
In troubleshooting, I set the variable as 10 as default, and then changed it. Although, ClassB still thinks of the variable as 10 in this case. I think the issue is with updating the variable, although I'm not entirely sure...
Here's the code for ClassA...
And here's what the code looks like for ClassB...
public int question;
public class ClassA extends Actor
{
public int question;
public int size = 25; // size of text for child classes
public int nonRepeat = 1;
public void act()
{
if(nonRepeat == 1)
{
questions();
nonRepeat = 2;
}
}
public void questions()
{
if(Greenfoot.getRandomNumber(3) == 0)
{
setImage("AAA-3.png");
question = 0;
getImage().setTransparency(100);
}
else if(Greenfoot.getRandomNumber(3) == 1)
{
setImage("AAO-1.png");
question = 1;
getImage().setTransparency(100);
}
else if(Greenfoot.getRandomNumber(3) == 2)
{
setImage("AAO-4.png");
question = 2;
getImage().setTransparency(100);
}public class ClassB extends ClassA
{
public void act()
{
setImageIncorrect();
}
public void setImageIncorrect()
{
if(answer == 0)
{
setImage(new GreenfootImage("EAE-1", size, Color.WHITE, Color.BLACK));
}
else if(answer == 1)
{
setImage(new GreenfootImage("AAA-3", size, Color.WHITE, Color.BLACK));
}
else if(answer == 2)
{
setImage(new GreenfootImage("IAO-2", size, Color.WHITE, Color.BLACK));
}

