12/15/22 Update: Thanks @KyleDev for the answer and explanation!
Kyle explained the snippet from the docs that was confusing me. I’m summarizing the convo here or you could also read the comments for more info:
The snippet from the docs:
for (Index := 0..MyArray1.Length-1):
if (Element := MyArray1[Index]):
Log("{Element} in MyArray1 at index {Index}")
This loops through the array, printing the element and the index of the array to the log. (Side not, for me Log doesn’t work and I need to either use Logger.Print or Print)
Within (Index := 0…MyArray1.Length-1):, Index := 0 signifies the first element in the array, and MyArray1.Length-1 signifies the last element of the array. The -1 is because in Verse the index starts at 0 instead of 1.
If I want to print a specific element of the array I can specify the index like this:
OnBegin<override>()<suspends>:void=
Logger.Print("Array_Test device started")
for (Index := 0..MyArray1.Length-1):
if (Element := MyArray1[1]):
Logger.Print("{Element}")
In MyArray[1], the number 1 is the index of the element I want to print. Technically this will be the second element in my list not the first, because the index starts with 0.
A separate issue is that in my initial code I should have written Print({Element})
instead of Print("{Element}")
Oops. Ended up using Logger.Print instead of Print anyway the Print() text disappears too fast.
Also, the script does print Element 2 three times in a row, instead of once, so I still want to figure out why that is and how to change it. I tried adding an else statement but then my script broke and I need to take a break before trying again.
===========================================================================================================================
12/15/22 Original Question:
Hey, so this should be extremely simple but I’m having a hard time understanding the Verse documentation on arrays. Thanks in advance for the help!
For my dialogue script with Verse UI, I want editable arrays of strings that I can change from the details panel. Similar to the editable array setup in @HugoMeta4 's subtitle system but I’m starting simple. All I need right now is to grab strings from the elements in my editable array, by index, and print them in the UI widget. I don’t need help with UI API atm, because I already learned how to create and edit the widgets, studying Hugo and @RayBenefield 's snippets.
This is a test I tried, which is wrong:
@editable MyArray1: []string = array{}
OnBegin<override>()<suspends>:void=
Print("Array_Test device started")
for(Element, MyArray1)
if(Element := MyArray1[1]):
Print("hi")
I understand from the docs that in order to access elements from arrays I need to be in a failure context, so I tried putting things in an if statement but I’m confused.
I get an error after print saying: “Expected expression or “)”, got “{” in parenthesized parameter list”
So then I tried Printing just (“hi”) and I see an error saying " Can’t use built-in macros other than to invoke them."
The examples in the docs for Arrays, and in the snippets from the Snippet Repository are more complicated than what I want to do, and I can’t yet figure out how to adapt the code for my case. https://dev.epicgames.com/documentation/unreal-editor-fortnite/en/0Jpo/Verse/array-in-verse
Thanks!