Copy link to clipboard
Copied
So I have this counter that I made which basically counts points but it also subtract points. sometimes in certain conditions the counter goes below zero and then I get a weird number 4294967266. my goal is to make counter remember negative numbers but if it's too defunct at least to stop at Zero. Any Ideas?
here is my counter:
//Scoreboard starts here:
var score: uint;
score = 100;
scoreBoard.text = "" + score.toString();
button_10.addEventListener(MouseEvent.CLICK, on_press1);
button_11.addEventListener(MouseEvent.CLICK, on_press2);
//Positive button adding points
function on_press1(event: MouseEvent): void {
gotoAndStop(2);
score += 100;
scoreBoard.text = "" + score.toString();
gotoAndPlay(61);
}
//Negative button subtracting points
function on_press2(event: MouseEvent): void {
score += -20;
scoreBoard.text = "" + score.toString();
}
//Scoreboard ends here:
I've got it! the variable should be int and not uint. like so
var score: int;
Copy link to clipboard
Copied
Just have an if statement which checks to see if it is less than or equal to zero - if so... override the display to 0 no matter what the actual number is or force the number.
Copy link to clipboard
Copied
that would be easy but every time it goes below zero it turns into this number 4294967266 which is obviously not smaller than zero and not a negative zero. who to avoid this number?
Copy link to clipboard
Copied
Always the same number? Perhaps there is something else going on in the code? You could look for that number and set a breakpoint for when it occurs to inspect what is going on.
Copy link to clipboard
Copied
yup it's always the same number when it goes below zero. However it does the math correctly when I click on the plus button it will go to normal numbers after it goes back to above zero. I'd upload the file for you to look if I knew how. but here is the script if you can look at it and figures it out.
import flash.text.TextFormat;
import flash.text.TextField;
var score: uint;
score = 0;
scoreBoard.text = "" + score.toString();
stop();
//Scoreboard starts here:
button_10.addEventListener(MouseEvent.CLICK, on_press1);
button_11.addEventListener(MouseEvent.CLICK, on_press2);
//Positive button adding points
function on_press1(event: MouseEvent): void {
score += 100;
scoreBoard.text = "" + score.toString();
}
//Negative button subtracting points
function on_press2(event: MouseEvent): void {
score -= 20;
scoreBoard.text = score.toString();
}
//Scoreboard ends here:
Copy link to clipboard
Copied
I've got it! the variable should be int and not uint. like so
var score: int;