Unexpected "Identifier" in class body

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

When I try to call a function, it says “Unexpected “Identifier” in class body.”


var list = ['a', 1, 'b', 2, 'c', 3]

func qwerty():
   for i in list:

qwerty() #error
:bust_in_silhouette: Reply From: jgodfrey

You can’t have a bare, top-level function call (like your error line). I’m not sure what you’re trying to do there exactly, but that function needs to be called from within another function. So, for example, you could make that call from _ready()

:bust_in_silhouette: Reply From: Cyber-Kun

It’s because your trying to run a function where there isn’t supposed to be one

you can write functions like this

func _ready():
     print(function_to_call()) #will print the return value of funtion_to_call()

function_to_call() #will not work because you can't just call a function it                   #                   needs to be called from within another function

func function_to_call():
    var value = 2/3
    return value