Opt-In Selection Pool Device
21,095 Views
-
using { /Fortnite.com/Characters } using { /Fortnite.com/Devices } using { /UnrealEngine.com/Temporary/Diagnostics } using { /Verse.org/Random } using { /Verse.org/Simulation } # Selects a random subset of Count elements from Elements and returns an array of the selected elements. # If Count is greater than the number of elements in Elements, all elements are returned in a random order. # This function uses parametric types, a feature of Verse. Parametric types allow you to specify arguments without a specific type. # This means that expressions can be more "generic" and operate on the arguments as long as those operations are supported by the type. # In this case, we don't need to know the type of each element in Elements to operate on the array, so we can use Shuffle and Slice on any type "t". # For more information, see https://dev.epicgames.com/documentation/en-us/uefn/Verse/parametric-types-in-verse SelectRandomElements<public>(Elements:[]t, Count:int where t:type):[]t= # Shuffle the Elements so they're in random order when we pick them. RandomElements := Shuffle(Elements) # Slice returns an array from StartIndex (first argument) to StopIndex (second argument). # Since the elements are in random order, this will return a random subset of Count elements from the start. if (Selection := RandomElements.Slice[0, Count]): Selection # If the Slice operation succeeds this is the last expression of the function, which is used as the implicit return. else: # If there are less than Count elements in the array, return all elements. They'll be in random order. RandomElements
You're reading a preview
The full reference is free for BrainDeadGuild Discord members — sign in to read it all, or open the original at the source.
Sign in with your BrainDead.TV / BrainDeadGuild Discord account for full access.