I was trying to store in the save files the unix time in the system to later create a "Continue" button that load the latest save file calculated from each file unix time. But when I store the unix time float in disk using ResourceSaver it does some weird rounding:
This is a small replication project:
Button.gd
extends Button
func _on_pressed() -> void:
var savefile :SaveFile = SaveFile.new()
savefile.dict["unix_time"] = Time.get_unix_time_from_system()
savefile.dict["float"] = 1708498594.489 # This is not the same value as the current unix time
savefile.f = 1708498594.489 # This is not the same value as the current unix time
print(" -- savefile unix_time in memory: ",savefile.dict.unix_time)
print(" -- savefile float in memory: ",savefile.dict.float)
print(" -- savefile f in memory: ",savefile.f)
await ResourceSaver.save(savefile,"res://savefile_dict.tres")
savefile = load("res://savefile_dict.tres")
print("\n -- savefile unix_time in disk: ",savefile.dict.unix_time)
print(" -- savefile float in disk: ",savefile.dict.float)
print(" -- savefile f in disk: ",savefile.f)
SaveFile.gd
extends Resource
class_name SaveFile
@export var dict :Dictionary
@export var f :float
It prints this:
I tried to use randf but it always defaults to 1708500000, maybe because randf returns a float.
Does anyone know why this happens? or how to solve it?