On_input event not working? (SOLVED)

I recently started using Defold and by recently I mean 2 days ago. I am getting to the scripting part after figuring out everything else, but I encountered a problem.

This code doesn’t work and being new to this engine I cant really figure out why…
Its very simple im just trying to run a new animation when a key is pressed.

local RunningAnimation = 1

function init(self)
	msg.post(".", "acquire_input_focus")
	
end

function on_input(self, action_id, action)
	print("Fired1")
	if action_id == hash("Toggle_Move") and action.pressed == true then
		print("Fired2")
		if RunningAnimation == 1 then
			print("Fired3")
			msg.post("#sprite", "play.animation", {id = hash("Walking") })
			RunningAnimation = 0
		else
			print("Fired4")
			msg.post("#sprite", "play.animation", {id = hash("Idle") })
			RunningAnimation = 1
		end
		return true
	end
end

It prints all 4 print statements and no errors as well but the animations never seem to change.

Does anyone have any ideas?

Thank you for your time!

– Solved –
I have since fixed the problem :slight_smile:

Great that you managed to solve the problem on your own. What was wrong?

So on the part where it says

msg.post("#sprite", "play.animation", {id = hash("Walking") })

I had a period in play.animation instead of an underscore. I was using a different engine that used periods for everything previously so its just habit.

2 Likes