# Keeping data between rounds

**URL:** <https://forums.unrealengine.com/t/keeping-data-between-rounds/1135793>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [April 21, 2023, 1:49pm UTC](https://forums.unrealengine.com/t/keeping-data-between-rounds/1135793 "2023-04-21T13:49:57Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guedin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/guedin/32/1194721_2.png) [@Guedin](https://forums.unrealengine.com/u/Guedin)\
**Post date:** [April 21, 2023, 1:49pm UTC](https://forums.unrealengine.com/t/keeping-data-between-rounds/1135793/1 "2023-04-21T13:49:57Z")

</div>

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

```auto
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")
```

---

<div class="post-metadata">

**Author:** ![FinestCreative](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finestcreative/32/1034971_2.png) [@FinestCreative](https://forums.unrealengine.com/u/FinestCreative)\
**Post date:** [April 21, 2023, 2:14pm UTC](https://forums.unrealengine.com/t/keeping-data-between-rounds/1135793/2 "2023-04-21T14:14:10Z")

</div>

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

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/f/7/9f70e061513094bb289f656797dee87e59c477bb.png)

---

<div class="post-metadata">

**Author:** ![FinestCreative](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finestcreative/32/1034971_2.png) [@FinestCreative](https://forums.unrealengine.com/u/FinestCreative)\
**Post date:** [April 21, 2023, 2:17pm UTC](https://forums.unrealengine.com/t/keeping-data-between-rounds/1135793/3 "2023-04-21T14:17:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![FinestCreative](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finestcreative/32/1034971_2.png) [@FinestCreative](https://forums.unrealengine.com/u/FinestCreative)\
**Post date:** [April 21, 2023, 2:17pm UTC](https://forums.unrealengine.com/t/keeping-data-between-rounds/1135793/4 "2023-04-21T14:17:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Guedin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/guedin/32/1194721_2.png) [@Guedin](https://forums.unrealengine.com/u/Guedin)\
**Post date:** [April 21, 2023, 10:34pm UTC](https://forums.unrealengine.com/t/keeping-data-between-rounds/1135793/5 "2023-04-21T22:34:03Z")

</div>

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 😉

---

<div class="post-metadata">

**Author:** ![FinestCreative](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finestcreative/32/1034971_2.png) [@FinestCreative](https://forums.unrealengine.com/u/FinestCreative)\
**Post date:** [April 21, 2023, 11:09pm UTC](https://forums.unrealengine.com/t/keeping-data-between-rounds/1135793/6 "2023-04-21T23:09:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Guedin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/guedin/32/1194721_2.png) [@Guedin](https://forums.unrealengine.com/u/Guedin)\
**Post date:** [April 21, 2023, 11:10pm UTC](https://forums.unrealengine.com/t/keeping-data-between-rounds/1135793/7 "2023-04-21T23:10:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Creeeper](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Creeeper](https://forums.unrealengine.com/u/Creeeper)\
**Post date:** [April 24, 2023, 9:14pm UTC](https://forums.unrealengine.com/t/keeping-data-between-rounds/1135793/8 "2023-04-24T21:14:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![TruongBui](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/truongbui/32/743871_2.png) [@TruongBui](https://forums.unrealengine.com/u/TruongBui)\
**Post date:** [September 3, 2023, 10:47am UTC](https://forums.unrealengine.com/t/keeping-data-between-rounds/1135793/9 "2023-09-03T10:47:35Z")

</div>

You can keep data between rounds using Global Variables now [Constants and Variables](https://dev.epicgames.com/documentation/en-us/uefn/variables-in-verse#globalvariables)

---

<div class="post-metadata">

**Author:** ![TruongBui](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/truongbui/32/743871_2.png) [@TruongBui](https://forums.unrealengine.com/u/TruongBui)\
**Post date:** [September 6, 2023, 8:46am UTC](https://forums.unrealengine.com/t/keeping-data-between-rounds/1135793/10 "2023-09-06T08:46:08Z")

</div>

FYI, Here is my usage example of Global Variables

```auto
# 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.

---

<div class="post-metadata">

**Author:** ![Mapshot\_Agency](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mapshot_agency/32/700660_2.png) [@Mapshot\_Agency](https://forums.unrealengine.com/u/Mapshot_Agency)\
**Post date:** [October 5, 2023, 8:11am UTC](https://forums.unrealengine.com/t/keeping-data-between-rounds/1135793/11 "2023-10-05T08:11:36Z")

</div>

Hey Truong,

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

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

```auto
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}")

```

---

<div class="post-metadata">

**Author:** ![Mapshot\_Agency](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mapshot_agency/32/700660_2.png) [@Mapshot\_Agency](https://forums.unrealengine.com/u/Mapshot_Agency)\
**Post date:** [October 5, 2023, 9:11am UTC](https://forums.unrealengine.com/t/keeping-data-between-rounds/1135793/12 "2023-10-05T09:11:47Z")

</div>

But according to the documentation [session class](https://dev.epicgames.com/documentation/en-us/uefn/verse-api/versedotorg/simulation/session)

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

---

<div class="post-metadata">

**Author:** ![t.tutiya](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/t.tutiya/32/924637_2.png) [@t.tutiya](https://forums.unrealengine.com/u/t.tutiya)\
**Post date:** [October 5, 2023, 9:25am UTC](https://forums.unrealengine.com/t/keeping-data-between-rounds/1135793/13 "2023-10-05T09:25:43Z")

</div>

For more infomation.

> [@MAJOR weak\_map GetSession() broken in 26.10](https://forums.unrealengine.com/t/major-weak-map-getsession-broken-in-26-10/1292369/10):
>
> This is unfortunately intended. Use of session as a key in a module-scoped var weak\_map may eventually gain back support for cross-round state (hence the scary “Note: …” part of the doc), but it was removed in 26.10. To protect against a behavior change (when cross-round state is added back), make sure to initialize your state at the beginning of OnBegin in a creative\_device, e.g. if: set GlobalInt[GetSession()] = 0
