0 votes

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? enter image description here

Godot version 3.4
in Engine by (17 points)

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.

What should i in this case then?

How do make a function that loads the data?

1 Answer

0 votes

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 savelevel_ 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)
by (1,789 points)

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

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.