How to add scores to all live players on each player elimination?

I’d like to add a point to each live player whenever a player is eliminated. I did the following in my Verse device:

  1. I added and bound the Score Manager:
    @editable ScoreManager : score_manager_device = score_manager_device{}
  1. I have a map that tracks which players are eliminated:
    var PlayerMap : [fort_character]player_prof = map{}
  1. I subscribe to all players’ eliminated events and initialize the map:
    OnBegin<override>()<suspends>:void=
        AllPlayers := GetPlayspace().GetPlayers()
        for (Player : AllPlayers, Agent := agent[Player], Fort := Agent.GetFortCharacter[]):
            Player.EliminatedEvent().Subscribe(OnEliminated)
            if (set PlayerMap[Fort] = false) {}
  1. In OnEliminated, I set that the player was eliminated and use that bound score manager to add points to all non-eliminated players:
    OnEliminated(Elim0: elimination_result): void =
        Fort := Elim0.EliminatedCharacter
        if (P := PlayerMap[Fort]; set PlayerMap[Fort] = true):
            AllPlayers := GetPlayspace().GetPlayers()
            for (Player : AllPlayers, Agent := agent[Player], Fort2 := Agent.GetFortCharacter[], Fort2_eliminated := PlayerMap[Fort2], not (Fort2_eliminated?)):
                    ScoreManager.Increment(Agent)
                    ScoreManager.Activate(Agent)

Now, this works, but I found that when I have a game with 3+ players, it will sometimes log “VerseRuntimeErrors: Error: internal error occurred.” and the script will stop working. I’m not sure what exactly causes this error. Besides this happening with 3+ players, it seems to occur when two players are eliminated around the same time. I don’t know if it’s possible for UEFN to give more details on the internal error, but my blind guesses are:

  • A bug of the concurrent map modification (I guess this shouldn’t occur based on the UEFN docs);
  • A bug of having the fort_character type in the map (I saw some posts here or on Discord mentioning that having players, unlike primitive types, stored in a map could be problematic in the current UEFN version);
  • A bug of accessing the map around the round end: I set it to be the “last man standing”, so a round should end when there’s only one player left, and I again saw some posts mentioning issues when accessing data around the round end…

For completeness, I added logs in different places and the last message before “VerseRuntimeErrors” was when adding the scores… I also tried removing the ScoreManager and adding the points in a custom map, and still hit that issue, so it seems it’s not due to the ScoreManager, but the map access.

Any other ideas? Or is there a different way to achieve the same thing?

This happens to me 50 times a day since the new update, are you using weak_map() somewhere in your code ? (see Verse global variables no longer working, even on previous uploads)

Nope, just regular maps, but I saw those posts mentioning issues with weak_map after the recent update.

Uhm, do you know what the ‘;’ does, I see you’re using it instead or ‘,’ ?

Also maybe remove the parentheses here : not (Fort2_eliminated?)

Tried that and still the same :cry:

it turned out it was due to activating modulator device on eliminated players in a separate task, so far ok (hopefully).

1 Like