A while loop "crashing"/freezing my game

Yes its me again with my stupid questions
My question now I’m trying to make the character move when condition is met but when I debug it the game goes all white here code(I’m using the loop in update function):

while self.position ~= vmath.vector3(298.7503, self.position.y, self.position.z) do
		self.position.x = self.position.x - 30 * dt
		go.set_position(self.position)
	end

You should avoid equality comparisons between floats due to floating precision.
Your text “298.7503” probably won’t be represented as that when running.

You should rather use “>” or “<” when checking such bounds.

More info here

1 Like

ERROR: attempt to compare two userdata values
What should I change? (This is after I changed ~= to > )

Why are you doing that in a loop? It will not smoothly animate if that is what you are expecting. Can’t you just use go.animate()? Or do a single set_position?

I have never used go.animate(), you know a better way how to make the character go back to it’s original position while a condition is met?

On my phone:

local duration = 1
go.animate(".", "position.x", go.PLAYBACK_ONCE_FORWARD, 298.735, go.EASING_LINEAR, duration)

O thanks this function is pretty useful

1 Like