i cant save and load data

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

i have been trying all day to save and load data so that exiting the game does not take you back to level 1 by my code does not work anyone can help?

And what is this code supposed to do ? THere are two functions here, one saves integer to a file, another read it from file. There is no function to actually use loaded variable to update your openlevs var.

Inces | 2022-01-07 09:57

What should i in this case then?

kitsune | 2022-01-07 10:49

How do make a function that loads the data?

kitsune | 2022-01-07 12:52

:bust_in_silhouette: Reply From: DaddyMonster

This code looks fine. The only issue is that you’re sending “data” in as an argument and as a member variable (there will be a warning about this in the console): remove the var data = openlevs line.

You just need to call your methods. Let’s say you want to save when you press F5 and load when the game starts.

Loading

func _ready():
    openlevs = load_val()

Saving

Go to project → project settings → input map (tab)
Enter save_level into “action field”, click add. Find “save_level” at the bottom of list, click “+”, then “key” and press F5.

func _input(event):
    if event.is_action_pressed("save_level"):
        save_val(openlevs)

Thank you! I am very grateful
I have been trying for 3 days now.
You saved me(no pun intended)
May god bless you

kitsune | 2022-01-07 13:47

Glad it helped. It’s all too easy to hit a brick wall when you first start. If you have free time in the evenings, try working through this excellent YouTube series, it should give you a solid grounding in the core concepts:

https://www.youtube.com/watch?v=xjB0H3BgzTI&list=PLJ690cxlZTgIsmdEhFufnB7O6KWoMS8M6

DaddyMonster | 2022-01-07 14:17