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β
Entry point
1 / 2Why 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