Release a button

I’m really new to this engine, but previously made pretty same game on PSP lua engine. Sources are already lost, and I don’t remember how to code Lua, so, I am actually a newbie again. The question is, how to make game read the button input only once, even if I hold the key. Hope for your assist, folks. Here’s the code:

function init(self)
	msg.post(".", "acquire_input_focus")
	self.move = vmath.vector3()
	self.job = false
end

function final(self)
	-- Add finalization code here
	-- Remove this function if not needed
end

function update(self, dt)
	

	self.move.x = 0
end

function on_message(self, message_id, message, sender)
	-- Add message-handling code here
	-- Remove this function if not needed
end

function on_input(self, action_id, action)
	if action_id == hash("leftstep") then 
		self.move.x = -10
		
	end
end


function on_reload(self)
	-- Add reload-handling code here
	-- Remove this function if not needed
end
1 Like

Hi and welcome!

You should be able to check the released field of the action table inside the on_input callback! Something like this:

...
    if action_id == hash("leftstep") and action.released then 
...

:slight_smile:

More info here: https://www.defold.com/ref/go/#on_input:self-action_id-action
And here: https://www.defold.com/manuals/input/

3 Likes

Maaaan, thank you a lot, I was sitting about two days with this, didn’t thought it could be so easy! :smiley:

5 Likes