Range Over Built in GDScript
On this page
Here we use for
to sum the numbers in an array.
Explanation
To run the program, simply put the code into a script in your Godot project and attach it to a Node. The _ready
function will automatically run when the scene is ready.
Let’s break down what this script does:
Summing Numbers in an Array:
This segment creates an array of integers and sums them using a
for
loop.Finding Indexes in an Array:
This segment demonstrates how to find and print the index of a specific value in the array.
Iterating Over Dictionary Key/Value Pairs:
Here, we iterate over the key/value pairs in a dictionary and print them.
Iterating Over Dictionary Keys:
This loop only prints the keys of the dictionary.
Iterating Over Characters in a String:
Finally, we iterate over each character in a string and print its index and the character.
By running this script within your Godot project, you can observe the various ways to iterate over different data structures and print relevant information. Now that you understand these iterations, you can explore more about the GDScript language and its capabilities.