6
« on: October 17, 2013, 01:28:11 am »
I'm trying some simple dragging along a line code
var vx, vy, vx1, vy1, x1, y1, x2, y2, mag, px, py :Float;
var XY = ( getGameAttribute("CoOrds")[0]).split(",");
x1 = XY[Std.int(0)];
y1 = XY[Std.int(1)];
var XY = ( getGameAttribute("CoOrds")[1]).split(",");
x2 = XY[Std.int(0)];
y2 = XY[Std.int(1)];
vx = x2 - x1;
vy = y2 - y1;
mag = Math.sqrt(vx*vx + vy*vy);
vx = (vx / mag);
vy = (vy / mag);
on the last 2 lines it complains and says: "Float should be Int"
however - if I assign the vx/mag to a new variable: e.g. vx1 (which is also a float)
vx1 = (vx / mag);
vy1 = (vy / mag);
it works perfectly.
Now, this is a work around - but I'd love it if someone could explain to me what's going wrong when I try to assign a value to a variable when dividing itself.