My Touch Input (Android) suddenly stopped working after building

Anderoo99Anderoo99 Posts: 74Member
edited October 27 in 2D

I had written a code which was working perfectly but suddenly it stopped working. Still works when I emulate mouse touch in my PC.

Here is the code

extends Node

var touch_col
var is_active = false

var evt

func _ready():
    touch_col = get_child(0).get_child(0)
    touch_col.disabled = true

func _process(_delta):
    if evt != null:
        get_node("TouchInput").global_position = evt.global_position

func _input(event):
    evt = event
    if event is InputEventScreenTouch:
        print("OK")
        is_active = !is_active
        if is_active:
            touch_col.disabled = false
        else:
            touch_col.disabled = true

Tags :

Best Answer

  • Anderoo99Anderoo99 Posts: 74
    Accepted Answer

    Hey, I was able to solve it. Just had to change global_position to position in line 14

Answers

  • wombatstampedewombatstampede Posts: 149Member

    I actually don't know what you want to achieve with "is_active".

    InputEventScreenTouch has an attribute "pressed". Maybe use that?
    There's also the attribute index which indicate which "#paralleltouch" that specific event is for. So when touching with two fingers there maybe overlapping touchevents pressed=true -> pressed=false with different index values. Maybe save the index of the first pressed=true event and only react to pressed=false when the event index matches or something similar.

    You save any event from _input for use in _process. Maybe you should save only InputEventScreenTouch events (put evt=... inside the if). And maybe only save the position.

  • Anderoo99Anderoo99 Posts: 74Member

    @wombatstampede said:
    I actually don't know what you want to achieve with "is_active".

    InputEventScreenTouch has an attribute "pressed". Maybe use that?
    There's also the attribute index which indicate which "#paralleltouch" that specific event is for. So when touching with two fingers there maybe overlapping touchevents pressed=true -> pressed=false with different index values. Maybe save the index of the first pressed=true event and only react to pressed=false when the event index matches or something similar.

    You save any event from _input for use in _process. Maybe you should save only InputEventScreenTouch events (put evt=... inside the if). And maybe only save the position.

    Hey, thanks for answering. I actualy need is_active for my other script. This script worked fine until recently. It still works when I emulate touch screen in godot.

    Here are some errors that are shown whn I build the game.

    Unicode error: invalid skip
    Unicode error: invalid skip
    Unicode error: invalid skip
    Unicode error: invalid skip
    Unicode error: invalid skip
    Unicode error: no space left

  • Anderoo99Anderoo99 Posts: 74Member
    edited October 29

    I ran logcat and god this error

    10-29 22:46:32.014 13717 13738 E godot : SCRIPT ERROR: Invalid get index 'global_position' (on base: 'InputEventScreenTouch').
    10-29 22:46:32.014 13717 13738 E godot : At: res://Scripts/InputManager.gdc:15:_process() - Invalid get index 'global_position' (on base: 'InputEventScreenTouch').

    get_node("TouchInput").global_position = evt.global_position // line 14 of input script

  • Anderoo99Anderoo99 Posts: 74Member
    Accepted Answer

    Hey, I was able to solve it. Just had to change global_position to position in line 14

  • wombatstampedewombatstampede Posts: 149Member

    To say it again:
    I propose that you move evt=event two lines lower inside the if block unless you want _process to actually work on every (even non-touch) event that triggers _input().

  • Anderoo99Anderoo99 Posts: 74Member

    @wombatstampede said:
    To say it again:
    I propose that you move evt=event two lines lower inside the if block unless you want _process to actually work on every (even non-touch) event that triggers _input().

    I will do that :-)

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file