How to use an array in a function (Verse)

I am trying to use an array in a function without directly referring to it so I can reuse the function for other arrays, but I don’t know how to do that. Any easy fix / solution for this?

weighteditemgrant := class<concrete>():                                 # The class that stores the item granter and weight
    @editable Granter : item_granter_device = item_granter_device{}
    @editable Weight : int = 0




# A Verse-authored creative device that can be placed in a level
verse_weaponrandomiser := class(creative_device):

    @editable TriggerInput : trigger_device = trigger_device{}

    @editable ShotgunArray : []weighteditemgrant = array {}
    @editable RangedArray : []weighteditemgrant = array {}
    @editable HealingArray : []weighteditemgrant = array {}
    @editable MobilityArray : []weighteditemgrant = array {}
    @editable DefenseArray : []weighteditemgrant = array {}
    @editable MiscArray : []weighteditemgrant = array {}

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        # TODO: Replace this with your code
        TriggerInput.TriggeredEvent.Subscribe(DeviceActivated)               # At game start, subscribe the device to the corrosponding trigger

    DeviceActivated(MaybeAgent : ?agent) : void=                             # MaybeAgent is the instigator? Will have to check
        Print("WeaponRandomiser Activated")
        PickFromArray(ShotgunArray)

    PickFromArray(UsedArray : array {} , MaybeAgent : ?agent) : void= #Expected a type, got array value instead
        var TotalWeight : int = 0

This is just a simple syntax error. To take an array as a parameter, you have to use this syntax:

Func(Name: []Type):ReturnType=

So, if we wanted to construct a simple function that would find the sum of any given array, we would do this:

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

array_parameters := class(creative_device):
    FindSum(Numbers : []int):int=
        var Sum : int = 0;
        
        for (Number : Numbers):
            set Sum += Number;

        return Sum;

    OnBegin<override>()<suspends>:void=
        Print("{FindSum(array { 1, 2, 3, 4 })}")

10

In your case, you wouldn’t use an int, you’d use a weighteditemgrant. So, the function declaration would look like this:

PickFromArray(UsedArray : []weighteditemgrant, MaybeAgent : ?agent):void=
    # logic
1 Like