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":
funcselect_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)
Become an Indie Gamedev with GDQuest!in GDSchool
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.