Constant
2025/12/27
- Type
- Learning Resource
- Format
- Glossary Article
- Version
- General
- Subject Tags
- Created
- Updated
- 2026/02/16
- 2025/12/27
A constant is a variable whose value can never change. It's a tool to give a name to a specific value, which in turn can make the code easier to read and the value easier to reuse in different places.
In computer code, we often work with values that have a different meaning depending on the context. For example, the number 100 could be the player movement speed, their maximum health, or the number of coins they need to collect to gain an extra life.
By defining a constant, if this value never changes in the game, you can make the purpose of this value clear.
In the GDScript language, you can create a constant with the const keyword. By convention, we write the name of constants with uppercase words separated by underscores. When reading long code files, this helps to instantly recognize constants. Here are three examples:
const SPEED := 100
const MAX_HEALTH := 100
const COINS_FOR_EXTRA_LIFE := 100Don't stop here. Step-by-step tutorials are fun but they only take you so far.
Try one of our proven study programs to become an independent Gamedev truly capable of realizing the games you’ve always wanted to make.
Get help from peers and pros on GDQuest's Discord server!
20,000 membersJoin ServerThere are multiple ways you can join our effort to create free and open source gamedev resources that are accessible to everyone!
Sponsor this library by learning gamedev with us onGDSchool
Learn MoreImprove and build on assets or suggest edits onGithub
Contributeshare this page and talk about GDQUest onRedditYoutubeTwitter…