How do i save multiple variables on the player's device ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By EmileBowtie

So i have a game where you complete Burger orders you’re customers give you , you earn money for that , and you can use that money to buy a new restaurant location to play in . And so i decided that i need to get the money collected my the player saved in the ‘money_collected’ variable , so that you can access that variable at any point in any script . AND also save the dictionary containing the key’s for the restaurant’s you unlocked or can unlock . Specifically , every key’s value in that dictionary can be a number from 1 to 3 . 1 meaning that the restaurant needs to be bought , 2 that its bought but not equipped currently and 3 means its bought and equipped . So if the restaurants’ key’s value is 3 . It means the scene of gameplay will be in that restaurant .

And so , i wrote a script for this all , and in fact it did work properly , but it only saves ‘money_collected’ variable ( or so at least i think ) . Because in the game the value of this variable does react to being changed and saved . But the dictionary doesn’t , so i don’t know if its saved or not . But i think not , since if for example i print - if location_data[“BurgerTown”]==3: print(“true”) . It in fact , does not print true , even known the value of mentioned key is 3 .

And the main problem is in the store , when you buy and equip the restaurant’s , it SHOULD obviously work . There is no other way around it . So I’ve been researching and struggling with this problem for a week now , and i decided that i better get help from people who may actually know the answer . So PLEASE if you do , here are some screenshots of scripts where the problem occurs yet they should be working . I would be extremely thankful for any help !

Screenshots :

Btw here is my Discord btw Shin1949#5799

EmileBowtie | 2023-05-20 04:21

:bust_in_silhouette: Reply From: zhyrin

In your first _process() function, save_data() is indented to the else block. Which means you’ll only save the data when a game over occurs. You’ll want to bring it outside 1 level of indentation, that way it runs regardless of “RightCONT” or “GameOver” being true.

I also recommend you put a breakpoint in your code and step through the script line by line in debug mode when you expect a write to / read from file to happen, that way you can see how your game is actually running.
It’s more conveinient to look at the values of variables as the game is running as opposed to printing them out.

zhyrin | 2023-05-19 20:51

You might also want to write to a text-based file, that way you can easily confirm if you wrote every correct value to disk.

zhyrin | 2023-05-19 20:53

Well , here . I tried putting save and load everywhere . Still does not work , i even put it in the shop code everywhere - ![enter image description here][comment2-2]

But even known the “RETROdiner” key in the dictionary is equal to 2 -

The button is still white ( the button should be white only when the value is equal to 1 , when its equal to 2 it should be light-green ) YET , AS YOU CAN SEE FROM THE LEFT TOP CORNER , the ‘money_collected’ IS saved , and CAN be used everywhere . -

Here is the code that explains why the button should not be white ( buybutton is white , equipped is dark green , equip is light-green ) -

EmileBowtie | 2023-05-20 04:12

Here , tried to debug during the save_data , and here’s the debugger of the game in process https://cdn.discordapp.com/attachments/605680290555494401/1109337222257328230/image.png

Like , dictionary is there a think , but idk if it gets saved or not . Like it just says - dictionary size . Maybe that is the problem ? Maybe it saves its size and not the values . Idk , I’m bad at debugging .

EmileBowtie | 2023-05-20 04:31

While debugging, you can click on a dictionary variable where it says its size, and it will expand to show the keys and values.
You should also debug loading.

zhyrin | 2023-05-20 07:33

I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE !
I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE ! I FIXED IT , DONT NEED HELP ANYMORE THANKS TOU EVERYONE WHO CLICKED HERE !

EmileBowtie | 2023-05-21 05:32

What was the solution?

zhyrin | 2023-05-22 06:46