Unexpected token: if

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By S JaK

Here is my code and I don’t have any idea what is wrong with if:

extends Node2D
var left_pos = get_node("guy").get_pos()
if Input.is_action_pressed("move_right"):
    left_pos.y += 10
func _ready():
    pass
:bust_in_silhouette: Reply From: volzhs

you can’t write code outside of function, except define variable.
you need to move it inside of function.

for example

extends Node2D

var left_pos = get_node("guy").get_pos()

func _ready():
    pass

func _process():
    if Input.is_action_pressed("move_right"):
        left_pos.y += 10

I suggest you to read document for GDscript.

Thanks a lot! That solved my problem.

S JaK | 2018-09-24 16:55