Parse Error: Unexpected token: Identifier: add_child

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

Hello, first of all I am a novice, I was following a video tutorial, which is from a year ago, and my view of Godot is different from his. Anyway, when I want to create a child in the code I get the following error: Parse Error: Unexpected token: Identifier: add_child
PS: I speak Spanish

var A = Auto.instance()
add_child(A) <here is the mistake

:bust_in_silhouette: Reply From: Zylann

Your snippet doesn’t look wrong, as a snippet. However it can be wrong depending on the surroundings, which unfortunately you didn’t post.

If what you posted is indeed the only text there is in your script, then yeah, it’s wrong. You cannot use add_child alone, outside of a function or variable assignment.
Calls like add_child (or any other) can only be done from inside a function declared with func, or after an assignment with =.

Surely the tutorial you are following is calling add_child from inside a function (like _ready, _process, or other).