I´m using Godot FileAcess system to save and load data for my game, but I don´t know how do can I load a float value?
using the Myfloat= myfile .get_var(Myfloat) not works
Code:
### Godot Version 4.5
var FileSlot = "user://FileSlot.txt"
var Myfloat :float
func _ready() -> void:
if FileAccess.file_exists(FileSlot):
var myfile = FileAccess.open(FileSlot, FileAccess.WRITE)
Myfloat= myfile .get_float(Myfloat)
:ERROR: (X)
Line 15:Too many arguments for "get_float()" call. Expected at most 0 but received 1.
You want to read from a file, but you are opening it for writing instead of opening it for reading. Opening for writing will also effectively erase the contents of your file.
get_float() does not take an argument. It reads the next four bytes in the file, and returns them as a float.
FileAcess.get_float() does not accept any arguent. FileAccess keeps an internal read cursor and FileAcess.get_float() will read the next float from the file and advance the cursor 4 bytes.