![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | andrymas |
What did i do wrong?
![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | andrymas |
What did i do wrong?
![]() |
Reply From: | jgodfrey |
It’s really difficult to provide targeted answers about your code when you didn’t post your code. However…
The store_line()
method takes a string as an argument, as documented here:
https://docs.godotengine.org/en/stable/classes/class_file.html#class-file-method-store-line
Based on the error you posted, you’re apparently trying to pass in an integer
instead of a string
. To fix that, you can convert your integer
to a string
via the str()
function.
So, rather than something like this (which will cause the error you mention):
var a = 1
save_file.store_line(a)
You need something like this:
var a = 1
save_file.store_line(str(a))
Sorry for not including the code, i forgot about it, by the way this answer helped me finding the error. Here’s my code for tracking and saving the money count.
extends Node
var monete = 0
func _ready():
load_coins()
func load_coins():
print("Loading...")
var save_file = File.new()
if not save_file.file_exists("user://savefile.save"):
print("Aborting, no savefile")
return
save_file.open("user://savefile.save", File.READ)
monete = int(save_file.get_line())
save_file.close()
func save_level():
print("Saving...")
var save_file = File.new()
save_file.open("user://savefile.save", File.WRITE)
save_file.store_line(str(monete))
save_file.close()
print("saved")
andrymas | 2021-01-06 23:16