Arrays in functions

I’m currently attempting to streamline my code by utilizing arrays as function parameters. However, I’ve encountered an error that’s perplexing me. Here’s how my code looks at the moment:
@editable var Barriers : barrier_device = array{}
@editable var Teleporters : teleporter_device = array{}

InitMode(BarrierIDX: [ ]int, TeleporterIDX: [ ]int) : void =
    if (CurrentMode = "1vs1" or CurrentMode = "2vs2"):
        if (Barrier := Barriers[**BarrierIDX**]):
            Barrier.Enable()
        if (Teleporter := Teleporters[**TeleporterIDX**]):
            Teleporter.Enable()

My objective is to enable or disable certain barriers and teleporters when a specific game mode is selected. Since this game mode employs numerous teleporters and barriers, I’m attempting to condense the code by using arrays. When calling the InitMode function, I only intend to specify which teleporters or barriers should be enabled or disabled. However, I’m encountering an error regarding BarrierIDX and TeleporterIDX, which states:

“No overload of the function operator'()' matches the provided arguments (:barrier_device,:int). Could be any of:
function (/Verse.org/Verse:)operator’()‘(:t,:int)
function (/Verse.org/Verse:)operator’()‘(:ref t,:int)
function (/Verse.org/Verse:)operator’()‘(:ref [t]u,:t)
function (/Verse.org/Verse:)operator’()‘(:weak_map(t, u),:t)
function (/Verse.org/Verse:)operator’()'(:ref weak_map(t, u),:t)(3509)
(Also tried with extension function arguments (:Boxfights,:tuple(),:tuple(barrier_device,int)))(3509)”

Any assistance would be greatly appreciated!

Hi.
The function expects two arrays with int values. Is that what the caller is sending? From the error, it looks like only one array with int values is being sent and the other is something else.

So I’m guessing it’s not working because one is sending an array of int values and the other is sending an array of barriers and teleporters? How could I change that or is there another way to access certain barriers and teleporters when working with arrays like that? The code Im working with above is basically all I have rn.

couldnt you just iterate thought each array enabling and disabliung without having to send the array as the barrier and teleporter arrays are global variable you can just access them


InitMode() : void =
    if (CurrentMode = "1vs1" or CurrentMode = "2vs2"):
        for (Barrier : int = 0..Barriers.Length):
            Barrier.Enable()
        for  (Teleporter : int = 0..Teleporters.Length):
            Teleporter.Enable()

Wouldn’t this activate all barriers? I would then have to specify which barriers or teleporters should be activated. I’ll have a look at your solution though. Many thanks for that!

yes it would, maybe create a temp array of barriers to enable and parse that

I think I’m going to take a different approach. I want to have a dropdown menu in my gamemanager where I can select any mode (in this case 1vs1 or 2vs2) and in each of those modes, I want to be able to select different barriers and teleporters to activate.

Along the way, however, I’m wondering if it’s possible to access different classes in such a dropdown menu. Essentially, I’ve created a class with a specific game mode (in this case, Boxfights) and in the game manager class itself, I’m now trying to create the dropdown menu I envisioned. I tried it with the kind of code shown below:

Game_Boxfights := class():
var CurrentMode : string = “No game mode selected”
@editable var Barriers : barrier_device = array{}
@editable var Teleporters : teleporter_device = array{}

Mode_1vs1() : void=
    set CurrentMode = "1vs1"

Mode_2vs2() : void=
    set CurrentMode = "2vs2"

gamemanager := class(creative_device):
@editable Boxfights : Game_Boxfights = CurrentMode{}

After trying many different approaches, I still can’t get it to work. Any suggestions?

The correct way would be

for (BarrierID : BarrierIDX, Barrier := Barriers[BarrierID]):
    Barrier.Enable()

Would even be better if you passed an array of barriers instead of passing an array of barrier indexes

Thank you! At the moment I am trying this approach:
for (Barrier : Barriers):
Barrier.Enable()

Is that what you are talking about? Or what do you mean when you talk about passing an array of barriers?