Menu
CoddyTech

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

In this lesson's scene, the robot's speed is set to 90 in the Inspector.

challenge icon

Challenge

Easy
  • Make an exported variable speed, with a default of 200.
  • Move the robot right at speed pixels 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
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Nodes and Scenes

Practice on your own: Godot playground