0 votes

What did i do wrong?

Godot version 3.2.3
in Engine by (25 points)

1 Answer

+2 votes
Best answer

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))
by (21,656 points)
selected by

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")
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.