Select random device array with no repeats

Hey! I’m working on some code in Verse and I’m stuck on how to get it right.

I want to create an array of trigger devices. When the game starts, a random trigger should be activated, but in the next round, it shouldn’t be the same as the last one. Is there a way to do this?

This is what I have right now and it doesn’t work:

    @editable MountainIndex:[]trigger_device = array{}
    var LastMountainSelection:weak_map(session, int) = map{}

    OnBegin<override>()<suspends>:void=
        RandomizeMountain()


    RandomizeMountain():void=
        mountainIDX:= GetRandomInt(0, MountainIndex.Length - 1) 
        X := if (Y := LastMountainSelection[GetSession()]) then Y + mountainIDX else 0
        if (mountainIDX = X):
            Print ("Rerolling mountain...")
            RandomizeMountain()
        else:
            for (Index := mountainIDX..MountainIndex.Length - 1):
                if (Element := MountainIndex[Index]):
                    Element.Trigger()
                    if:
                        set LastMountainSelection[GetSession()] = X
                    Print("This Mountain selection was {X}")
1 Like

There isn’t a great way to do this at the moment due to the fact that you can’t save data between rounds. I’m hoping this comes soon because it would really help a TON of people with map creativity.
There may be some real round-about ways to do this. I see your attempt at the Session map. You probably realized it resets after each Round. I think this is in the request queue for Session to remain between rounds. I haven’t been able to find any device workarounds at the moment to persist the data. I actually decided to go the “Player Vote” route on this issue instead of random. :-/

If I come across a solution, I’ll definitely post something.

-MF

Okay, thank you!

Guess what. As requested. This must be new?!

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