Ready Runs Once
Part of the Nodes and Scenes section of Coddy's Godot journey. Lesson 2 of 28.
Godot calls _ready() once for each node, when the node joins the game. Use it for what a node does when it appears, like setting its place or printing a greeting.
Lines inside a function run from top to bottom. These two print() calls write two lines in the Console, in this order:
func _ready():
print("First")
print("Second")Every line inside a function starts with a tab (the Tab key). The tab tells Godot the line belongs to the function. A line with no tab is outside it, and Godot stops with an error such as Unexpected identifier "print" in class body.
Challenge
EasyMake the robot print two lines when the game starts.
- Keep
print("Robot online")as the first line of_ready(). - Under it, add a second
print()with words of your own, for exampleSystems ready. Start it with a tab.
Press Play: the Console shows Robot online, then your line. Then Check.
Try it yourself
extends Node2D
func _ready():
print("Robot online")
All lessons in Nodes and Scenes
1Your First Godot Game
What Is Godot?Ready Runs OncePrint in GodotThe Scene TreeSet a PositionMove a Node OncePractice on your own: Godot playground