0 votes

I tried following the GDScript Tutorial, the starting one, in the documentation, where you add a panel and then a label and a button as children of the panel. Upon making the script for the panel and writing the code, the result is an error instead of "Hello!"

I deleted my code and instead copy/pasted the code from the tutorial, and it also gave the same error. So I'm wondering if the tutorial is up to date or if I somehow could have missed something.

  • I created a panel.
  • I created a label.
  • I created a button.
  • I made sure to make the label and the button children of the panel.
  • I clicked the panel and added a script.
  • I copy pasted the code from the tutorial into it.
  • I saved the scene, set it to main after it insisted, and ran it.
  • Error.

Thank you. I was unsure how to find the error and copy it here.

in Engine by (32 points)

Some are, but (and I'm gestimating here) most are not. This isn't a big problem though as most of the version 1 info is still relevant to version 2. Copying and pasting the script and error message here would help me in solving your problem with you.

Thanks for replying. This is the tutorial: http://docs.godotengine.org/en/latest/tutorials/step_by_step/scripting.html

And the code in question is this one:

extends Panel

func onbuttonpressed():
get
node("Label").set_text("HELLO!")

func ready():
get
node("Button").connect("pressed",self,"onbutton_pressed")

I'm not sure why the getnode isn't showing an underscore here, but I use it when writing the real script.

I assume the italic words are where underscores where. This is a non-static scripting language, did you add indents after the function declarations? If not then indent the get_node() s

When you copy and paste from the docs, it often leaves out true indents and inserts 4 to 8 blank spaces instead.

Thanks for that. When I entered the code, it automatically indented the code for me on the next line:

func onbuttonpressed():
get
node("Label").set_text("HELLO!")

func ready():
get
node("Button").connect("pressed",self,"onbutton_pressed")

*its not showing the indent in the preview here but it's really indented

So, I don't understand where my mistake is. I have the label and button as children of the panel, added the script to the panel. I'm just not sure if I'm missing something, but I could have sworn I followed each step precisely. Hmm, stumped here.

Why don't you try taking a snapshot of your editor's node tree and see what the debugger's explanation for the crash is. You might need a upload site like pintrest or deviant art to have the image show here.

Well I did it again for the third time and it all worked. What did I do differently? I have no idea. I think I may have saved my script in the wrong place the first time? I don't know. I'm still trying to figure out the best way to save stuff in this engine.. Thanks for your help.

If you don't mind, can you tell me how to set my custom layout to open every time I start a new project? I always have to set it myself which seems unusual that Godot wouldn't remember it. I can save the layout and select it, but Godot never uses it as default.

If I have to make a new question for this, I will. Thanks!

I'm sure it's possible. You will probably need to make a custom build though. The rest of the community might give you away to make your layout default without compiling the engine.

How odd. I own Construct 2 and use Unity and both open with whatever layout I saved. Oh well, no biggie. Thanks for all your help!

Not sure if you figured out the default layout question, but I think if you save over the 'Default' layout, it will load that up each time.

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.