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(): 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. GetFirstGem(): string = # We get the gem at index 0. # This is the first item in the list. # Note: indexing a Verse array is a failable expression, # so we use 'if' to safely unwrap it. if (FirstGem := Gems[0]): return FirstGem return ""