0 votes


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.

in Engine by (26 points)

1 Answer

+1 vote
Best answer

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://"

by (9,776 points)
selected by

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?

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

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.

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

That led to a fix. Thank you!

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.