So I have an actor that has 11 different possible images/costumes, each for a different digit and an extra which is just a black square. If a value is equal to 4, the actor should switch to "num4.png," and look like a 4. This works, but only once. If the value changes to say 8 while the program is running, the actor stays as a 4. If I change the starting value from 4 to say 6, it will become a 6 when the program starts but will stay as a 6 even if the variable changes. I don't know how to fix this and it's been really annoying.
Here's my code.
Possible images that digit1 can be are num0.png to num10.png. 10 is just a black square.
The value is stored in an array, but digit1 will only look at the second value, hence why iam = 1;
My code is mostly incomplete, so this might seem a bit weird, I dunno. But any help as to why Digit1 won't change appearance more than once would be nice.
Also the idea of the array is that eventually, {4560,0,0,1230,0,0,0} etc will become {0,6,5,4,3,2,1}, but because the second value is a 0, Digit1 will switch to num0.png and when it's finished changing and the second array value is 6, digit1 is still using num0.png and not num6.png.
import greenfoot.*;
public class Digits extends Actor
{
int digits = 27;
int[] mA = {4560,0,0,1230,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0}; // Value 0 isn't shown ingame, nor is value 28.
public void act()
{
for (int i = 0; i < 28; i++) //if mA[0] <= -1, WHOLE number is negitive. If mA[28] >= 1, Interger overflow.
{
if (mA[i] <= -1)
{
mA[i+1]--;
mA[i] += 10;
}
if (mA[i] >= 10)
{
mA[i+1]++;
mA[i] -= 10;
}
}
}
public void adjustMoney(int m, int d) // m = money to add, d = what digit the money should be added to.
{
mA[d] += m;
}
}import greenfoot.*;
public class Digit1 extends Digits
{
static int iam = 1;
public void act()
{
if (mA[iam] > 9 || mA[iam] < 0 || iam > digits)
setImage("num10.png");
else
setImage("num" + mA[iam] + ".png");
}
}
