Whats the difference between a Array & Generator in Verse?

Recently, the function GetCreativeObjectsWithTag was deprecetad, the new FindCreativeObjectsWithTag returns a Generator instead a array, and we cant acess index in this generator

what’s the main difference? and what’s the best pratice to work with tags in classes that are not creative devices?

Hi VETZ, generators can only be used inside for loops, which means you can’t ask for an element at a certain index or ask for the generator length
Also all the array functions are not available in generators

This change is only relevant because they found multiple performance issues regarding arrays, in the future there’s no point in using generators instead of arrays

A := []int

for(Element : A) { } # Works
Size := A.Length # Works (but is not performant rn)
if(FirstElement := A[0]): # Works if there's atleast one element in the array

B := generator(int){}
for(Element : B) { } # Works
Size := B.Length # Doesn't work
if(FirstElement := B[0]): # Doesn't work

Array functions you can’t use in generators (as of 32.00)

    (Input:[]t where t:type).Slice<public>(StartIndex:int, StopIndex:int)<computes><decides>:[]t = external {}
    (Input:[]t where t:type).Slice<public>(StartIndex:int)<computes><decides>:[]t = external {}
    (Input:[]t where t:type).Insert<public>(InsertionIndex:int, ElementsToInsert:[]t)<computes><decides>:[]t = external {}
    (Input:[]t where t:type).RemoveElement<public>(IndexToRemove:int)<computes><decides>:[]t = external {}
    (Input:[]t where t:subtype(comparable)).RemoveFirstElement<public>(ElementToRemove:t)<computes><decides>:[]t = external {}
    (Input:[]t where t:subtype(comparable)).RemoveAllElements<public>(ElementToRemove:t)<computes>:[]t = external {}
    (Input:[]t where t:type).ReplaceElement<public>(IndexToReplace:int, ElementToReplaceWith:t)<computes><decides>:[]t = external {}
    (Input:[]t where t:subtype(comparable)).ReplaceFirstElement<public>(ElementToReplace:t, ElementToReplaceWith:t)<computes><decides>:[]t = external {}
    (Input:[]t where t:subtype(comparable)).ReplaceAllElements<public>(ElementToReplace:t, ElementToReplaceWith:t)<computes>:[]t = external {}
    (Input:[]t where t:subtype(comparable)).ReplaceAll<public>(ElementsToReplace:[]t, Replacement:[]t)<transacts>:[]t = external {}
    (Input:[]t where t:type).Remove<public>(StartIndex:int, StopIndex:int)<computes><decides>:[]t = external {}
    (Input:[]t where t:subtype(comparable)).Find<public>(ElementToFind:t)<computes><decides>:int = external {}

    Concatenate<public>(Arrays:[][]t where t:type)<computes>:[]t = external {}
    Shuffle<public>(Input:[]t where t:type)<transacts>:[]t = external {}

This video might help:

What do you mean exactly with this? is getting the length not good performance wise on any array?

1 Like

It was hidden in the patchnote (inside the new verse procedural template)

1 Like