Keeping data between rounds

Hello there,

I’m looking for a way to keep data in-between rounds, like a int variable used for tracking Score through out several rounds

I tried this but the class get re-initialized every round and the Score is reset to 0

Thank you for your help

round_test := class(creative_device):
    @editable
    ButtonScore : button_device = button_device{}
    @editable
    ButtonEndRound : button_device = button_device{}

    @editable
    RoundDevice : round_settings_device = round_settings_device{}

    var SomeScore : int = 0

    OnBegin<override>()<suspends> : void=
        ButtonScore.InteractedWithEvent.Subscribe(HandleButtonScoreInteraction)
        ButtonEndRound.InteractedWithEvent.Subscribe(HandleButtonEndRoundInteraction)


    HandleButtonScoreInteraction<private>(Agent : agent) : void=
        set SomeScore += 1
        Print("Score : {SomeScore}")

    HandleButtonEndRoundInteraction<private>(Agent : agent) : void=
        RoundDevice.EndRound(Agent)

    HandleRoundBegin() : void=
        Print("Round Begin")

Set this to END OF GAME so it keeps the class you set in round 1

To save an int in beteween rounds the best I can come up with is at the end of a round grant all players some item, like a plant or crystal. Go in the round settings device and set Keep items in between rounds.

WHen the new round starts use conditional buttons to check which item the player has.

This method only works if you want to save a small int, like <50. Because you would need 50 conditional buttons and 50 item granters for this

1 Like

If you want have persisitent player score in between rounds I think the save device works

Thank you for your help!

Unfortunately the score manager doesn’t keep track of the score between rounds (I assume that’s what you were referencing to)
And the workflow with conditional buttons is an interesting one, but that’ll be a bit too much to manage.

Oh well, I’ll keep digging ideas on how I can achieve this result.
Thanks again :wink:

Then I don’t think you can save an int in between rounds. I have tried many things like using a tracker or timer but did not work, so went back to the old days of using the conditional buttons like we did years ago.

I did not refer the the score manager. I mean you can save the score in a save point device, and load it in the next round. But I dont know if the save point works in UEFN

ha I was not aware of this, I’ll give it a check, thanks

The save point is a disallowed object. How would you make it so all items can be dropped but the item used for tracking? and when a player dies in the game, how would they drop everything but the item used for tracking?

You can keep data between rounds using Global Variables now Constants and Variables

1 Like

FYI, Here is my usage example of Global Variables

# Track round number for this session
var RoundNumberMap : weak_map(session, int) = map{}

OnBegin<override>()<suspends>:void=
        # Set round number for each session
        Session := GetSession()
        if(RoundNumber := RoundNumberMap[Session]):            
            if(set RoundNumberMap[Session] += 1):
                Print("Current Round Number: {RoundNumber+1}", ?Duration := 5.0)              
        else:
            if(set RoundNumberMap[Session] = 1):
                Print("Initialize Round Number to 1", ?Duration := 5.0)

However, you cannot save the player variable in the global variable. You will encounter Verse runtime error if you try to retrieve the player variable in the next round. That means there is no way to know which data belongs to which player. Hope this helps.

1 Like

Hey Truong,

I was trying out this code, but it still seems to forget value after a round. Any additional insights you can share? :pray:

I’m trying to make a scoreboard that increments on elimination and consistent between rounds.

The score increases correctly, but after a round, the score is reset again

var ScoreTeamOne : weak_map(session, int) = map{}
var ScoreTeamTwo : weak_map(session, int) = map{}

HUDScoreboard := class(creative_device):

    @editable EM_eliminationManager_TeamOne :elimination_manager_device = elimination_manager_device {}
    @editable EM_eliminationManager_TeamTwo :elimination_manager_device = elimination_manager_device {}

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        Print("TEST DEVICE")

        EM_eliminationManager_TeamOne.EliminatedEvent.Subscribe(PlayerEliminatedTeamOne)
        EM_eliminationManager_TeamTwo.EliminatedEvent.Subscribe(PlayerEliminatedTeamTwo)

    PlayerEliminatedTeamOne(Agent : agent) : void = 
        X := if (Y := ScoreTeamOne[GetSession()]) then Y + 1 else 1
        if:
            set ScoreTeamOne[GetSession()] = X
        Print("Elminated Team 1: {X}")

    PlayerEliminatedTeamTwo(Agent : agent) : void = 
        X := if (Y := ScoreTeamTwo[GetSession()]) then Y + 1 else 1
        if:
            set ScoreTeamTwo[GetSession()] = X
        Print("Elminated Team 2: {X}")

But according to the documentation session class

A session is specific to a round and not persistent over rounds.

Type for which there is a single instance per round. Use GetSession to get the current round’s session instance. May be used with weak_map to implement global variables. Note: may be changed in a future release to a single instance per game. Round-local behavior should not be relied upon.

Which also explains my behavior in previous reply

1 Like

For more infomation.