![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | gummyrat |
So I’m working on a game and I followed this video to try and implement a save system. However, it is not updating. Here is my global script code, any help appreciated as I am a newbie.
extends Node2D
#default values
var jayson_index = 0
var brock_index = 0
var steven_index = 0
var jodi_index = 0
var gabe_index = 0
var town_index = 0
var jaysondoor_index = 0
var world_index = 0
func update_jayson_index():
jayson_index = jayson_index + 1
func update_brock_index():
brock_index = brock_index + 1
func update_steven_index():
steven_index = steven_index + 1
func update_jodi_index():
jodi_index = jodi_index + 1
func update_gabe_index():
gabe_index = gabe_index + 1
func update_town_index():
town_index = town_index + 3
func update_jaysondoor_index():
jaysondoor_index = jaysondoor_index + 1
func update_world_index():
world_index = world_index + 1
var game_data : Dictionary
func _ready():
update_data()
pass
func update_data():
game_data = { "playerdata":
{"jayson": jayson_index,
"brock": brock_index,
"steven": steven_index,
"jodi": jodi_index,
"gabe": gabe_index,
"town": town_index,
"jaydoor": jaysondoor_index,
"world": world_index}}
func do_save():
var file: File = File.new()
file.open("res://saved_game/game.dat", File.WRITE)
file.store_line(to_json(game_data))
file.close()
func do_load():
var file : File = File.new()
file.open("res://saved_game/game.dat", File.READ)
game_data = parse_json(file.get_as_text())
file.close()
func _physics_process(delta):
if(Input.is_action_just_pressed("save_key")):
do_save()
I use the update functions in different scripts but it doesnt change the value in the dictionary… when i do_save()
Not sure but I think that might be the problem.
func do_save():
var file: File = File.new()
func do_load():
var file : File = File.new()
you opened two files
Saving games — Godot Engine (stable) documentation in English
or
https://forum.godotengine.org/80759/how-to-save-objects-to-a-file-with-json
ramazan | 2022-01-20 08:53