This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

Hello from germany,
im new @ godot and an absolute beginner getting this error...

Whats wrong with this?

Godot Function

in Engine by (29 points)

1 Answer

+5 votes
Best answer

This doesn't work because you can't call your function at the top level of the class. I assume you have an extends line at the top that you just didn't copy and paste. You could call it when the program is run like this:

func _ready():
    my_function(12, 21)

But note that even then, you're discarding the return value, so you'd probably want something more like:

func _ready():
    var c = my_function(12, 21)
    print(c)

I don't know your level of programming experience, so If this doesn't make sense to you, I strongly suggest that you start with a beginner-level coding tutorial - Python would be my recommendation.

If you do know how to code, but you're just confused about Godot & GDScript, Step by step section of the official docs. There is a lot of important foundational material there.

by (22,191 points)
selected by

Hi kidscancode. Btw great tutorials, thanks for that.
I did the sololearn phton course (50%) and know a lot php/css/html.
That really helped everything work fine now, thanks.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.