I dont understand this error

function init(self) 
	msg.post(".","acquire_input_focus")
	self.runSpeed = 50
	self.curAnim = "idle"
	msg.post("#sprite", "play_animation", { id=hash("idle") })
	self.speed = vmath.vector3()
	particlefx.play("#playerparticle")
end
function update(self, dt)
	local pos = go.get_position()
	if self.speed.x ~= 0 then    
		pos = pos + self.speed * dt
		go.set_position(pos)
		if self.curAnim ~= "run" then
			msg.post("#sprite", "play_animation", { id=hash("run") })
			self.curAnim = "run"
		elseif self.curAnim ~= "idle" then
			msg.post("#sprite", "play_animation", { id=hash("idle") })
			self.curAnim = "idle"
		end
		end
	end
	self.speed = vmath.vector3()
end
function on_input(self, action_id, action)
	if action_id == hash("MOVE_RIGHT") then
		self.speed.x = self.runSpeed
		sprite.set_hflip("#sprite", false)
	end    
	if action_id == hash("MOVE_LEFT") then
		self.speed.x = self.runSpeed * -1
		sprite.set_hflip("#sprite", true)
	end        
end

It says compilation failed : β€˜β€™ expected near β€˜end’ what does that mean and how do i fix it

Its also on line 24

You have one too many ends?

1 Like

oh lol. I have another question can I ask you on this?

Yes, and you do not need to ask to ask!

1 Like

Okay well now when I move the run anim keeps playing even when im not moving

function init(self) 
	msg.post(".","acquire_input_focus")
	self.runSpeed = 50
	self.curAnim = "idle"
	msg.post("#sprite", "play_animation", { id=hash("idle") })
	self.speed = vmath.vector3()
	particlefx.play("#playerparticle")
end
function update(self, dt)
	local pos = go.get_position()
	if self.speed.x ~= 0 then
		msg.post("#sprite", "play_animation", { id=hash("idle") })
	if self.speed.x ~= 0 then    
		pos = pos + self.speed * dt
		go.set_position(pos)
		msg.post("#sprite", "play_animation", { id=hash("idle") })
		if self.curAnim ~= "run" then
			msg.post("#sprite", "play_animation", { id=hash("run") })
			self.curAnim = "run"
			self.curAnim = "idle"
		end
	elseif self.curAnim ~= "idle" then
		msg.post("#sprite", "play_animation", { id=hash("idle") })
		self.curAnim = "idle"
	end
	self.speed = vmath.vector3()
end
function on_input(self, action_id, action)
	if action_id == hash("MOVE_RIGHT") then
		self.speed.x = self.runSpeed
		sprite.set_hflip("#sprite", false)
	end    
	if action_id == hash("MOVE_LEFT") then
		self.speed.x = self.runSpeed * -1
		sprite.set_hflip("#sprite", true)
	end        
end
end

Oops thats the wrong code

function init(self) 
	msg.post(".","acquire_input_focus")
	self.runSpeed = 50
	self.curAnim = "idle"
	msg.post("#sprite", "play_animation", { id=hash("idle") })
	self.speed = vmath.vector3()
	particlefx.play("#playerparticle")
end
function update(self, dt)
	local pos = go.get_position()
	if self.speed.x ~= 0 then    
		pos = pos + self.speed * dt
		go.set_position(pos)
		msg.post("#sprite", "play_animation", { id=hash("idle") })
		if self.curAnim ~= "run" then
			msg.post("#sprite", "play_animation", { id=hash("run") })
			self.curAnim = "run"
			self.curAnim = "idle"
		end
	elseif self.curAnim ~= "idle" then
		msg.post("#sprite", "play_animation", { id=hash("idle") })
		self.curAnim = "idle"
	end
	self.speed = vmath.vector3()
end
function on_input(self, action_id, action)
	if action_id == hash("MOVE_RIGHT") then
		self.speed.x = self.runSpeed
		sprite.set_hflip("#sprite", false)
	end    
	if action_id == hash("MOVE_LEFT") then
		self.speed.x = self.runSpeed * -1
		sprite.set_hflip("#sprite", true)
	end        
end

Is the run animation set to loop or forward once?

Once forward

Try debugging your script by using print(thing) and pprint(table) anywhere you think values are not being set/unset properly.

1 Like