In short, I have no idea what I'm doing wrong. The fix is likely simple. Here's my project, poke around.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Daimoth
:warning: Old Version Published before Godot 3 was released.

I’m getting a null instance and I’m not sure why, it’s probably an order of operations problem that I just can’t seem to wrap my head around. One of you with a better understanding of when things actually take place when a Godot game launches will probably know immediately what I’m doing wrong.

:bust_in_silhouette: Reply From: volzhs

when I run game, nothing happens but mana is increased continuously when click a circle image.
is it expected?
when click a circle, there is an error, and can be fixed by changing 2 lines of code.

var mana_total = 0 # instead of [var mana_total]

func _process(delta):
    print("Mana total: ", mana_total) # instead of [print("Mana total: " + mana_total)]

and you’d better change SAVE_PATH to "user://" instead of "res://"

That helped a lot. In short, I’m trying to get it to save the mana_total. Upon closing and reopening the program, it fails to read the .dat file, which was apparently not written properly. Do you have any ideas regarding what I’m doing wrong there?

Daimoth | 2017-10-10 02:57

can’t open .dat file?
or problem to read / parse?

volzhs | 2017-10-10 05:15

Yes, it tells me there’s a UTF-8 error, or unicode error: invalid skip.

Try closing and opening the project again, it fails to load the mana_total value from the .dat file. Do you have any idea why this is the case? Thanks again, you’ve been a huge help.

Daimoth | 2017-10-10 14:17

it’s because you saved mana value by file.store_float(content)
but read it by file.get_as_text()
need to match same format.
try file.get_float() instead of file.get_as_text()

usually, file.get_as_text() is used with file.store_string()

volzhs | 2017-10-10 14:26

That led to a fix. Thank you!

Daimoth | 2017-10-10 17:28