I was testing how data saves work on the iOS and encountered a weird behavior.
What the app should do: by pressing a button it increments a value by 1 and saves it to a json file
What it actually does: saves the right value during the launch (checked through console), but when I quit and reopen, whatever value I have added during the last launch instance it doubles. An example would be it I had 53 and pressed the button 5 times it saved to 58. When I quit and reopen the value becomes 63.
I tried saving with encryption, but the behavior persists. I figure it must be on the Godot port side. Any ideas?
extends Control
var FILE_PATH = "user://data.json"
var save_data = {}
func _ready():
var valueint: int = 0
save_data.value = valueint
var file = File.new()
if file.file_exists(FILE_PATH):
file.open_encrypted_with_pass(FILE_PATH, File.READ, "savemelord")
save_data = str2var(file.get_as_text())
file.close()
$Button.text = str(save_data.value)
func _on_Button_pressed():
save_data.value += 1
var file = File.new()
file.open_encrypted_with_pass(FILE_PATH, File.WRITE, "savemelord")
var data_as_string = var2str(save_data)
file.store_string(data_as_string)
file.close()
$Button.text = str(save_data.value)