Found a bug in lua which I'm uncertain of why


#1

This is the code I’m using:

	local moveSpeed = self.maxSpeed

	loop
		local moveTo = {x=self.pos.x+moveSpeed, y=self.pos.y}
		if moveTo.x >= 118 or self:isPathClear(self.pos, moveTo) then
			self:move(moveTo)
		else
			if self.pos.y > 37 then
				moveTo = {x=self.pos.x, y=self.pos.y-moveSpeed}
			else
				moveTo = {x=self.pos.x, y=self.pos.y+moveSpeed}
			end
			
			if self:isPathClear(self.pos, moveTo) then
				self:move(moveTo)
			else
				self:say("I'm stuck...")
				self:wait(5)
			end
		end
		moveTo = nil
		self:wait(0.1)
	end

So what happens is, the movement starts, then the here just slides, and does nothing at all. If I change

	self:wait(0.1)

to

	self:wait(1)

there the hero keeps walking to the right, and everything works…

Edit:

	self:wait( 1-0.9 ) -- this works
	self:wait( 1/10 ) -- this doesn't
	self:wait( 1+0.1-1 ) -- works
	self:wait( 0.05+0.05 ) -- doesn't work
	self:wait( 1/2/5 ) -- doesn't work

	self:wait(-0.1) -- also works for some reason XD

lastly:

	local timer = 1
	timer = timer/10
	self:wait( timer )

doesn’t work either… :confused:
the same thing is for

	local timer = 0.1

etc

adding to that, this actually gives the error “Found an expression but expected a statement: while”

	local loopNumber = 0
	loop
		
		self:wait( 1 )
		
		loopNumber = loopNumber + 1
	end