Why can't I set this map value in Verse?

I’m confused as to why I can’t set the value of my TotalPlayerEliminations map. I get this syntax error “This invocation calls a function that has the ‘decides’ effect, which is not allowed by its context”. I assume I need some kind of weird ? operator, but I’m still trying to figure out how all that owrks.

    var InitialLoadoutWeaponGranter : item_granter_device = item_granter_device{}
    @editable
    var PlayerSpawner : player_spawner_device = player_spawner_device{}

    var TotalPlayerEliminations : [player]int = map{}

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        # TODO: Replace this with your code
        Print("Starting the Combat Pro Trainer")
        PlayerSpawner.SpawnedEvent.Subscribe(OnPlayerSpawn)
        Print("subscribed to spawn event")

    OnPlayerSpawn(InPlayer : agent) : void = 
        Print("A Player just spawned!")
        InitialLoadoutWeaponGranter.GrantItem(InPlayer)
        set TotalPlayerEliminations[InPlayer] = 0
       

I believe functions that can fail (ie are called using []) need to be inside an ‘if’ statement (to handle their failure case). You could try this:

if:
   set TotalPlayerEliminations[InPlayer] = 0
5 Likes

That did the trick, thank you! This failable concept is new to me, and I’ve been coding in different languages for 25 years! Always learning!

It was new to me as well! I’m still getting used to it :slight_smile:

Thank you for this. Was programming like I would in other languages and didn’t realize that anything that could fail needs to be in an if, spent an hour trying to figure it out… and to be fair to verse, probably smart to force this behavior as this means when code is shared it’s done in a way that is as bug free as possible. Seriously thanks again lol