Hi,
I have a simple game with some math… It generates a random number (which represents the number of villagers) to start with and then you can use buttons to add different jobs. For example if you start with 20 villages, you can press the farmer button to assign 1 to farmers and decrease 1 of the villagers.
now this is the code for the random number (just took the one out from the help in flash)
function randomInwoners(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
return randomNum;
}
var AantalInwoners2:Number
AantalInwoners2 = randomInwoners(5, 20)
aantalInwoners.text = AantalInwoners2
and this is the simple math I use, add 1 to the ‘boeren’ (farmers) and decrease ‘aantalInwoners2’ with 1…
var aantalBoeren2:Number = 0;
aantalBoeren.text = aantalBoeren2;
function telop1() {
aantalBoeren2++;
aantalBoeren.text = aantalBoeren2;
aantalInwoners2--
aantalInwoners.text = aantalInwoners2;
}
b1.onPress = telop1;
But everytime I press the button, it gives me the value of NaN. When I don’t use a random number, it does work… I’m not sure what I’m doing wrong.