# How to use an array in a function (Verse)

**URL:** <https://forums.unrealengine.com/t/how-to-use-an-array-in-a-function-verse/1611020>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [January 13, 2024, 12:51pm UTC](https://forums.unrealengine.com/t/how-to-use-an-array-in-a-function-verse/1611020 "2024-01-13T12:51:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Radical\_Red\_Head](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/radical_red_head/32/761240_2.png) [@Radical\_Red\_Head](https://forums.unrealengine.com/u/Radical_Red_Head)\
**Post date:** [January 13, 2024, 12:51pm UTC](https://forums.unrealengine.com/t/how-to-use-an-array-in-a-function-verse/1611020/1 "2024-01-13T12:51:56Z")

</div>

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?

```auto
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

```

---

<div class="post-metadata">

**Author:** ![EisStudios](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/eisstudios/32/885240_2.png) [@EisStudios](https://forums.unrealengine.com/u/EisStudios)\
**Post date:** [January 17, 2024, 5:04pm UTC](https://forums.unrealengine.com/t/how-to-use-an-array-in-a-function-verse/1611020/2 "2024-01-17T17:04:17Z")

</div>

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

```auto
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:

```auto
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:

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

```
