Input actions and detecting key/mouse press? (SOLVED)

hey guys, whats up? i need some help,

how can I have the button do an action just once even though I’m holding it?

for example: i want to create a button that makes my object jump and even though I’m holding the action happens only once.

On the input set a bool to true, and then at the end of your update set it to false. This bool would be for the initial jump. You will also want to track when you release the button to early exit the jump height if you want that feature.

function init(self)
	self.jumped = false
end

function update(self, dt)
	-- move character based on jump values
	self.jumped = false
end

function on_input(self, action_id, action)
	if action_id == hash("jump_key") then
		if self.jumped ~= true then
			-- update jump values
			self.jumped = true
		end
	end
end
1 Like

You can use action states, like :
action.pressed
action.released.
Example you can find here: https://www.defold.com/examples/input/down_duration/

4 Likes

thank you so much !! i helped!!

1 Like