Having trouble with calling a method in my code (Is calling the right word? Hope so.) It will return the correct variable which is a number between 0 and 10, but after running it again in a loop it always returns the same number, even if the variable it should be returning changes.
My code:
public class Digit1 extends Digits
{
static int iam = 1;
public void act()
{
setImage(getDigit(iam) + ".png");
}
}
Note that in Greenfoot, act() is run every tick (Is tick correct? It loops anyway.)
And my Method that won't return the right number:
public int getDigit(int heis)
{
if (heis > digits)
return 10;
else
{
switch(heis)
{
case 1:
return m1;
default:
return 10;
}
}
}
There are more cases, but my problem only involves heis = 1. m1 will be a number between 0 - 9, changing randomly as the code runs. Yet getDigit(iam) will only seem to return what it was when the code started running. What am I doing wrong?
Edit: So I kinda lied about m1 changing. It will but not properly yet. Right now it is set to a number, and counts downwards 1 at a time. If I set it to 5, getDigit(iam) returns 5, but later when m1 = 1, getDigit(iam) still returns 5.