Hi, I'm making a simple 2D platform game, I've set up a main menu (with New Game and Continue buttons) and a pause screen while in game (with Save, Resume and Menu) buttons.
My problem is: I can get my 'Save' button to produce a .DAT file in the required user folder stating 'World 1' in text but I'm not sure how to get this to then load the game from this point when I press the 'Continue' button on the main menu. I want the game to continue when I press the 'Continue' button from the scene I was at when I saved the game in the pause menu.
This is my 'main.gd' where my save/load scripts are stored (I have this set to autoload in project settings):
extends Node
var level = 1
var pause = false
func _ready():
_load()
func _save():
var data = ""
data += "World_ " + str (level)
var new_file = File.new()
new_file.open("user://save.dat", File.WRITE)
new_file.store_line(data)
new_file.close()
func _load():
var new_file = File.new()
if not new_file.file_exists("user://save.dat"):
_save()
return
new_file.open("user://save.dat", File.READ)
var data = new_file.get_as_text()
new_file.close()
data = data.split("\n")
for line in data:
if line.begins_with("level"):
level = int(line.split(" ")[1])
This is my MainMenu scene where my 'New Game' and 'Continue' buttons are:
extends Control
var main = load("res://main.gd").new()
func _on_PlayButton_pressed():
get_tree().change_scene("res://World_1.tscn")
func _on_ContinueButton_pressed():
main._load()
I've been through all the guides and documentation and I can't get any further.. Help would be much appreciated as I've been really struggling to get it to work! Thanks!