EDIT: Read my second post. It is shorted and get’s right to the point.
**[U]FIRST POST[/U]**
> ***Some weeks ago i started a project with great enthusiasm but I had a little holiday and forgot about it :(. I now found the project lying in an old corner of my computer and decided to come back to it. The problem is that there is one piece of code that i was having problems with back then and it is the only code i don't understand/remember. When the program is run this piece of code crashes the program. If anyone has any idea on what i was trying to do or if anyone has a better way of moving my player, it would be very helpful if ya could tell me :D.***
(It is run every frame if the player is significantly far away from the mouse)
private function movePlayer(newa)
{
trace(_player.x)
trace(_player.y)
trace(newa)
olda=[_player.x, _player.y]
trace(olda)
stepx=newa[0]-olda[0]
stepy=newa[1]-olda[1]
stepy2=0
stepx2=0
trace(stepx)
trace(stepy)
while (stepx2!=stepx || stepy2!=stepy)
{
if (stepx2/stepx < stepy2/stepy)
{
stepx2+=1
if (stepx > 0)
{
_player.x+=1
}
else
{
_player.x-=1
}
}
else
{
stepy2+=1
if (stepy > 0)
{
_player.y+=1
}
else
{
_player.y-=1
}
}
}