using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
# This is our device. It is like a box for our code.
GemCounterDevice := class(creative_device):
# This is our array. It holds gem names.
# We start with an empty list.
# Note: class fields in Verse are immutable by default;
# we use 'var' so we can reassign the array when appending.
var Gems : []string = array{}
# This runs when the game starts.
OnBegin<override>()<suspends>: void =
# Let's add some gems to the list!
# In Verse, arrays are value types. To "append" we
# concatenate a new single-element array and store
# the result back into our var field.
set Gems = Gems + array{"Ruby"}
set Gems = Gems + array{"Emerald"}
set Gems = Gems + array{"Sapphire"}
# Now let's look at all the gems.
# We use a 'for' loop to visit each one.
for (Gem : Gems):
# This prints the gem name to the debug log.
# You can see this in the output window.
Print("Found a gem: {Gem}")
# This function shows how to get a specific gem.
Verse Library
verse
01 Device
Shows how to create, append, iterate, and safely index arrays in Verse devices.
verse-library/verse-arrays-to-keep-track-of-many-things-at-once/01-device.verse
Sign in free to read the full source 🌴
This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.