0 votes

(Sorry for my english i'm using google translator)
I got this error "Invalid type in built-in function 'store_string' in base" _File ". Cannot convert argument 1 from float to String."

extends Node

var experion = 0
var hp = 100
var level = 0
var your_exp = 0

var sf = File.new()

const gamedata = 'user://gamedata.txt'

func save():
   sf.open(gamedata, File.WRITE)
   sf.store_string(hp)
   sf.close()
   pass

func load():
    print('loaded')
    sf.open(gamedata, File.READ)
    hp = sf.get_as_text()
    sf.close()
    pass
in Engine by (60 points)

1 Answer

0 votes
Best answer

store_string only takes a variable of type string as an argument, hp has the type float.
you can convert hp to a string using the str function, so you should replace sf.store_string(hp) with sf.store_string(str(hp))

by (55 points)
selected by
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 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 webmaster@godotengine.org with your username.