Choosing random array index

Hello there!
I have 2 arrays in my code:

@editable DiscArray : []prop_manipulator_device = array{}
@editable DiscButtonArray:[]button_device=array{}

The button array is attached to the DiscArray, so like if I want to show up the DiscArray with an index of 0, it also enables a button out of the array with the index 0 & so on.

Currently the code works like, if there are for example 2 players there will spawn 1 disc & if there would be like 4 players it would spawn 3 discs, but currently it’s just showing the same disc’s over & over again, but I want it to choose a random index of the DiscArray & show it up.

Does anybody have an idea how I can implement it into this code? Here’s also the functions for the Discs:

    HideAllDiscProps():void=
        for(Index := 0..DiscArray.Length-1):
            if(L_Disc:=DiscArray[Index]):
                L_Disc.HideProps()
                if(L_Button:=DiscButtonArray[Index]):
                    L_Button.Disable()

    InitDefaultDiscArray():void=
        for(Index := 0..DiscArray.Length-1):
            set DefaultDiscIndexes = DefaultDiscIndexes + array{Index}
    
    SpawnDiscs(InDiscsToSpawn:int):void=
        set UnusedDiscs = DefaultDiscIndexes
        Shuffle(UnusedDiscs)
        for(Index := 0..UnusedDiscs.Length-1):
            if(L_DiscIndex:int = UnusedDiscs[Index]):
                Print("Wants to show Disc {L_DiscIndex}")
                if(L_Disc:=DiscArray[L_DiscIndex]):
                    if(Index<InDiscsToSpawn-1):
                        L_Disc.ShowProps()
                        Print("Showing Disc {L_DiscIndex}")
                        if(Button:=DiscButtonArray[L_DiscIndex]):
                            Button.Enable()
                        else:
                                L_Disc.HideProps()
                    else:
                        Print("Wants to show Disc {L_DiscIndex}, but that element index is invalid.")

It looks like you are trying to use the Shuffle function, but you aren’t assigning the shuffled array to a value.

Try something like the following:

set UnusedDiscs = Shuffle(UnusedDiscs)
2 Likes