Skip to main content

Chapter 1a - First script

Your first GDScript​

Every sandbox script starts the same way: extend SceneTree, put code in _init(), then quit().

extends SceneTree

func _init():
print("Hello Godot")
quit()
πŸ§ͺ Try it

Mini quiz β€” entry point​

Quiz

Entry point

1 / 2

Why must sandbox scripts call quit()?

Pick an answer to see if you are right.

Printing​

print writes to the output. Strings use double quotes. You can print several values in one call.

print("score", 12)
print("a", "b", "c")
πŸ§ͺ Try it

Challenge: print a product​

Complete _init so it prints the result of 6 * 7 (one number), then quits.

Indentation

Indent with 4 spaces (Tab in the editor inserts spaces). Click Reset if an old draft has broken indent.

Comments​

# starts a comment to the end of the line.

# This is a comment
print("still runs") # trailing comment

Exercises​

Three steps: print two lines, print a labeled score, then build a line from two variables.

Activity: Two lines

Print Hi on the first line and Ada on the second line.

Hi
Ada