Game initialization behaviour

Hello, I am from Indonesia and beginner in defold
I ask why this initialization script is behave not as i wanted

event click

this is my code

your code goes here


function on_input(self, action_id, action)
	if action_id == hash("touch") and action.released then
		label.set_text("/go#label1", "untouched")
	else 
		action.pressed = label.set_text("/go#label1", "touched")
		
	end
end



```lua

this is in my code editor

![code editor|690x411](upload://sKU9HOn6d72YO2TkZyVry5MOXbh.jpeg)

my question is why and how to solve it?

Hello! First of all, you are assigning “action.pressed” to a label, which won’t work. What you want to do is check if the action is pressed.

Secondly, are you using “acquire_input_focus”?

Something like this is what you want:

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

function on_input(self, action_id, action)
	if action_id == hash("mouse_button_1") and action.released then
		label.set_text("label", "untouched")
	end

	if action_id == hash("mouse_button_1") and action.pressed then
		label.set_text("label", "touched")
	end
end
1 Like

Ok thanks for your explanation

Yes i am not declare “acquire_input_focus” in function init()