I have a function which does some maths on two numbers but i seem to get NaN as a return for it…. I don’t know why though….. this is my function:
function mouseConvert(mousex,mousey){
console.log(mousex+ ' '+ mousey);
var x = (mousex + Data.offset_x) - (settings.width/2) - settings.offset_left;
var y = (mousey + Data.offset_y) - settings.offset_top;
var tx = Math.round((x + y * 2) / settings.grid) - 1;
var ty = Math.round((y * 2 - x) / settings.grid) - 1;
console.log(tx+ ' '+ ty);
return [tx,ty];
}
The console log output from the function shows:

Here is the value for Data and settings

Why is it not returning numbers but rather NaN ?
Well if the mouse positions are strings like
"0", consider:Becomes
The string
"0-32"will then attempted to be converted to a number when you do subtraction with- (settings.width/2). AndNumber("0-32")isNaN, after which everything becomesNaN.You should convert them to a number right at the beginning. Or rather, never convert them to strings in the first place, since the event object has them as numbers already…