Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Loading Save Not Resetting $Data #255

Closed
PinkPenguin418 opened this issue Apr 7, 2024 · 2 comments
Closed

[BUG] Loading Save Not Resetting $Data #255

PinkPenguin418 opened this issue Apr 7, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@PinkPenguin418
Copy link
Contributor

PinkPenguin418 commented Apr 7, 2024

Describe the bug
When you load a previous save, it does not reset the data object to previous state, it keeps current state.

To Reproduce
Steps to reproduce the behavior:

  1. set data.someNumber 2
  2. Manually Save
  3. set data.someNumber 3
  4. jump to some label
  5. Load Save
  6. display $data.someNumber
  7. Will show data.someNumber as 3

Expected behavior
I'd expect the data.someNumber to be a 2

Screenshots

Browser
Chrome, latest version

@PinkPenguin418 PinkPenguin418 added the bug Something isn't working label Apr 7, 2024
@PinkPenguin418
Copy link
Contributor Author

So I noticed a few things while digging into the code. Not sure if it's related but I saw that in game-save.ts the GlobalGameSave has data there as well as achievements. That feels odd as I expected to find "global" instead of "data" (per the documentation in save-and-load.md.

I tried changing that, but it didn't fix the problem, so I'm guessing more is at work here.

@PinkPenguin418
Copy link
Contributor Author

PinkPenguin418 commented May 3, 2024

So I did a lot more digging on this. What I've noticed is this situation only happens after you loaded a game. It would appear that load doesn't load a copy of the vm store from the save file but actually uses that vm from the save file. Which means any changes to the game after loading the file results to changes to the underlying save file. Obviously that's not great.

I eventually found the culprit in the code. The loadSaveData is passing data.data as a reference. Simply needed to add deepCopy(). I'll upload a fix. That being said, I'm willing to bet the same issue appears in the other stores, but I wasn't as keen to modify those as there might be a reason behind it.

PinkPenguin418 added a commit to PinkPenguin418/narrat-engine that referenced this issue May 3, 2024
@liana-p liana-p closed this as completed in d2cf05f May 9, 2024
liana-p pushed a commit that referenced this issue May 15, 2024
* fix: #235

* fix(#255): VM object referenced from save

* fix(#274): Add logic to store management to fix custom store save issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants