Bound Checks
2025/12/27
- Type
- Learning Resource
- Format
- Glossary Article
- Version
- General
- Subject Tags
- Created
- Updated
- 2026/02/16
- 2025/12/27
A "bound check" or "boundary check" is when you check if an index is within the bounds of an array.
For example, in the case of the following Array:
var characters := ["Donald", "Scrooge", "Goofy"]The following indices are valid:
characters[0]
characters[1]
characters[2]However, the following are not:
characters[3]
characters[4]
characters[1000]Trying to access those indices will not give you errors in the editor, because Godot cannot infer, or guess, how many items are in the array. But it will give an error at runtime.
Checking if the index we are using is actually valid, like so, is called a "bound check":
func select_character(character_index := 0) -> void:
if character_index < 0:
push_error("Index is invalid: it is lower than 0")
elif character_index >= characters.size():
push_error("Index is invalid: It is higher than the amount of characters")
else:
var selected_character: String = characters[character_index]
print("Selected character: " + selected_character)Don'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…