Menu
CoddyTech

Export Variables

Part of the Nodes and Scenes section of Coddy's Godot journey. Lesson 15 of 28.

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 = 200

The 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.

This lesson's scene sets the robot's speed to 90, as the Inspector would. The Scene tab under the game does not list exported variables, so you will not see it there.

challenge icon

Challenge

Easy

Let the scene set the robot's speed.

  1. At the top of robot.gd, add an exported variable speed with a default of 200.
  2. In _process(), move the robot right at speed pixels a second.

Press Play: the scene sets speed to 90, so the robot moves 90 pixels a second. Then Check.

Try it yourself

extends Node2D

func _process(delta):
	position.x += 200 * delta

All lessons in Nodes and Scenes

Practice on your own: Godot playground