Can't Enable/Disable Devices found through GetCreativeObjectsWithTag?

My game has many button devices that I need to enable and disable, and I don’t want to manually assign them to an array as that hurts my soul. I am trying to get all the buttons in my level with tag Button and then either disable or enable all of these buttons. Here is my code for gathering the buttons and casting them all to button_device and adding them to an array of button_devices:

var Buttons : []button_device = array{}
FindButtons():void =
        TempButtons := GetCreativeObjectsWithTag(Button{})

        var Iterator: int = 0
        for(TempButton : TempButtons):
            #cast to button
            if(ValidButton:= button_device[TempButton]):
                #Add to button array
                if(set Buttons[Iterator] = ValidButton):
                    set Iterator += 1

        Print("{Buttons.Length} TotalButtons")

Using this code it always Prints the correct length, so I know it collected all the buttons and added them to the array. However, when I then use a simple for loop to go through and disable each button, they will print confirmation that the button was disabled, but not actually disable:

if(Buttons[Num].Disable):
                    Print("Button {Num} Disabled")

What is most confusing in that when I make the array editable and manually assign the buttons, the same for loop works and they all properly disable. I have brought all this into an empty project and recreated this error, you can go ahead and try for yourself as well.
My question is basically am I doing something wrong here with my code or is this a bug? Are dynamically generated arrays in Verse somehow different than editable ones? Any help is greatly appreciated!

Forgot to add that even stranger, I use identical code to fetch creature_spawner_devices in my level in order to enable/disable them, and it works fine. However I have had this error with both button and switch devices.

Ok I have found the problem is not editable versus dynamically set array, but rather how the Button is referenced.
In my project I get a random number and then was doing

Buttons[Num].Enable

This wasn’t working, but for some reason when I use this code it works:

for(Index -> Button: Buttons):
            if(Num = Index):
                Button.Enable()
                Print("Enabled{Num}")

This code isn’t optimal and pains me a little but I guess it works, does anyone have any insight to why trying to access a member of the array didn’t work?

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.