I’m using Javascript on the Hypesonic battle. I’m trying to change my position, but whenever I add 1 or subtract 1 from my coordinates, the numbers get treated as strings and get concatenated.
When x is 12 and changex is -1
x = x + changex;
I expect the result to be 11, but what I get is “12-1”
I think there might be a bug. I’ve tried parstInt(x) and Number(x) and lastly I threw out the numbers and started using strings to control direction. x increments fine but y moves to 2 and then stays there. Code:
if (x >= (width-1)) {
changex = "left";
} else {
if (x <= 0) {
changex = "right";
}
}
if (changex=="right") { x++ } else { x-- }
if (y >= (height-1)) {
changey = "up";
} else {
if (y <= 0) {
changey = "down";
}
}
if (changey=="down") { y++ } else { y-- }
if (DEBUG) { printErr(changex, changey); }