bvbohnen / x4-projects

Parent repo for other X4 projects, with shared code for documentation and release generation.
MIT License
42 stars 12 forks source link

Data saved with md.Userdata.Write doesn't seem persistent #16

Closed kuertee closed 1 year ago

kuertee commented 1 year ago

Hey SirNukes, I seem to be having trouble saving persistent data across save files using md.Userdata.Write.

Attached is a test mod that only does these two things:

  1. using "md.Userdata.Read", read "$data_persistent" on or on . $data_persisten defaults to "table[]", so on the first install of the mod, it reads "table[]" to the script log.
  2. after 10s and every 10s, write increase a counter and save player.age in $data_persisten using "md.Userdata.Write". I do an "md.Userdata.Read" immediately to check the "md.Userdata.Write" worked.

Here's the script log on the first install of the mod on either a new game or a loaded game. This is as expected.

GameSession_Interval: $data_persistent (pre md.Userdata.Write): table[$counter_interval=1,$time=1083095.007s]
GameSession_Interval: $data_persistent (
[kuertee_test_sn_userdata.zip](https://github.com/bvbohnen/x4-projects/files/11076625/kuertee_test_sn_userdata.zip)
md.Userdata.Read for confirmation): table[$counter_interval=1,$time=1083095.007s]
GameSession_Interval: $data_persistent (pre md.Userdata.Write): table[$counter_interval=1,$time=1083105.022s]
GameSession_Interval: $data_persistent (md.Userdata.Read for confirmation): table[$counter_interval=1,$time=1083105.022s]
GameSession_Interval: $data_persistent (pre md.Userdata.Write): table[$counter_interval=1,$time=1083115.11s]
GameSession_Interval: $data_persistent (md.Userdata.Read for confirmation): table[$counter_interval=1,$time=1083115.11s]

But regardless of whether I start a new game or load a different game, $data_persistent returns the default "table[]" - meaning that the previous data that was saved didn't persist.

Mind having a quick look at this? kuertee_test_sn_userdata.zip

kuertee commented 1 year ago

Nevermind. It looks like that test fails because it occurs before the "md.Userdata.Reloaded" event. When the data is READ on "md.Userdata.Reloaded", it works.

bvbohnen commented 1 year ago

Thanks for the update on what was happening. I was a bit busy with work and was slow to get around to this issue.

kuertee commented 1 year ago

No worries, all good!