![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | pferft |
Hi everyone,
following Gonkee’s tutorial (https://www.youtube.com/watch?v=ldKFOGRQDzo&list=PLl29vQKblxBW8LOP-T4imEtYP0306DF60&index=24)
I set up a little project with a LineEdit
Label and two Checkboxes
. Tapping a SAVE Button
then actually does save the text and the on/off states (among many many other things…), but tapping the LOAD Button
won’t do a thing. On closing and opening the project again, everything is reset as well.
My game_save.gd
contains:
extends Resource
export(bool) var checkbox1_on_off
export(bool) var checkbox2_on_off
export(String) var text_in_label
The code in my overarching Node2D:
extends Node2D
export(Script) var game_save_class
var save_vars = ["checkbox1_on_off", "checkbox2_on_off", "text_in_label"]
func _ready():
pass
func verify_save(world_save):
for v in save_vars:
if world_save.get(v) == null:
return false
func load_world():
var dir = Directory.new()
if not dir.file_exists("res://saves/save_01.tres"):
return false
var world_save = load("res://saves/save_01.tres")
if not verify_save(world_save):
return false
$CheckBox.bool = world_save.checkbox1_on_off
$CheckBox2.bool = world_save.checkbox2_on_off
$Label.text = world_save.text_in_label
return true
func save_world():
var new_save = game_save_class.new()
new_save.checkbox1_on_off = $CheckBox
new_save.checkbox2_on_off = $CheckBox2
new_save.text_in_label = $Label.text
var dir = Directory.new()
if not dir.dir_exists("res://saves/"):
dir.make_dir_recursive("res://saves/")
ResourceSaver.save( "res://saves/save_01.tres" , new_save) # .res is binary, .tres is text
func _on_SAVE_button_up():
save_world()
func _on_LOAD_button_up():
load_world()
The things I’m not sure about to begin with are “bool” and “String” and “text” (in export() var and the load- and save-functions. How to find out what to use there, I wonder?
Help is much appreciated. What am I missing/doing wrong?
EDIT:
it’s of course
func _ready():
load_world()