How to do multitouch implementation

is the mouse input but im testing in the mobile phone

There is action data coming in that does not contain an action.touch table, i.e. that value does not exist.

Remove it. Thereā€™s a one touch only action coming in that allows you to have the same code for one-touch on mobile and mouse on desktop.

now i just use the loop when action.touch > 1, so the error dont happen but it still donā€™t jump

touch.action > 1 is probably not a good test. You can test against the number of elements in the table with:

if #touch.action > 0 then
    ...
end

Do the messages to the character get sent?

Edit: Can you post the whole function?

this is the function

> function on_input(self, action_id, action)
>     if action_id == hash("touch") and #action.touch > 0 then
>     	for i, tpoint in ipairs(action.touch) do
>    			local gui_right_arrow = gui.get_node("right")
>    			local gui_left_arrow = gui.get_node("left")
>    			local gui_jump_button = gui.get_node("jump")
>    			local gui_up_arrow = gui.get_node("up")
>    			local gui_down_arrow = gui.get_node("down")
> 			if gui.pick_node(gui_right_arrow,tpoint.x,tpoint.y) then
> 				msg.post("character#script", "right", {value=action.value})
> 				pprint(action)
> 			elseif gui.pick_node(gui_left_arrow,tpoint.x,tpoint.y) then
> 				msg.post("character#script", "left",{value=action.value})
> 			elseif gui.pick_node(gui_jump_button,tpoint.x,tpoint.y) then
> 				if action.pressed then
> 					msg.post("character#script", "jump")
> 					print("jump")
> 				elseif action.released then
> 					msg.post("character#script", "abortjump")
> 				end
> 			elseif gui.pick_node(gui_up_arrow,tpoint.x,tpoint.y) then
> 				--not used
> 			elseif gui.pick_node(gui_down_arrow,tpoint.x,tpoint.y) then
> 				--not used
> 		end
> 	end
> end

when i press jump and nothing else it works, if i pres first another node then character dont jump

DEBUG:SCRIPT:
{
x = 196.25,
touch = {
1 = {
x = 196,
tap_count = 0,
pressed = false,
y = 94,
dx = 0,
released = true,
dy = 0,
}
}
pressed = false,
y = 94.75,
screen_y = 190,
screen_dy = 0,
screen_dx = 0,
screen_x = 392,
dx = 0,
value = 0,
repeated = false,
released = true,
dy = 0,
}

Youā€™re looking at ā€œaction.pressedā€ and ā€œaction.releasedā€ instead of for the individual touches:

if action.pressed then
    msg.post("character#script", "jump")
    print("jump")
elseif action.released then
    msg.post("character#script", "abortjump")
end

should be:

if tpoint.pressed then
    msg.post("character#script", "jump")
    print("jump")
elseif tpoint.released then
    msg.post("character#script", "abortjump")
end
1 Like

Thank you so much!! What a stupid thing :sweat:

No worries. Easy thing to miss.

For thumbsticks or other implementations where touch order is of importance, it would be very helpful with an identifier attached to the touches. Especially if you want to move outside of the ā€œpick_nodeā€ area.

If you were to add colors to the multi-touch example, first spawning red colors and the second touch blue. Notice that releasing the first, would turn your second touch blue. To circumvent this error one would have to store away the previous touches and ā€œrestoreā€ in which order they were added, so that the second touch which you keep after releasing the first, still is considered the second touch, even tho #action.touch == 1

2 Likes