Export Variables
Part of the Nodes and Scenes section of Coddy's Godot journey. Lesson 15 of 27.
Put @export in front of a variable and Godot's editor shows it in the Inspector. The Inspector is the panel that lists the properties of the node you pick. You can change the value there without editing code:
@export var speed = 200The number in the script is the default. A value set in the Inspector is saved in the scene, and the node gets it when the game starts. Two robots with one script can have two speeds.
In this lesson's scene, the robot's speed is set to 90 in the Inspector.
Challenge
Easy- Make an exported variable
speed, with a default of200. - Move the robot right at
speedpixels a second.
The scene sets the speed to 90, so the robot should move 90 pixels a second.
Try it yourself
extends Node2D
func _process(delta):
position.x += 200 * delta
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Nodes and Scenes
1Your First Godot Game
What Is Godot?Ready Runs OncePrint in GodotThe Scene TreeSet a PositionMove a Node Once3Values You Can Tune
Variables on a NodeConstantsExport VariablesVector2 MathWrap Around the ScreenYour Own FunctionsPractice on your own: Godot playground