Help with an error

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Comet

(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
:bust_in_silhouette: Reply From: Noah Burck

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))