Saving a property into an external textfile? PROBLEM!

I need a highscore-system for my game (Space Invaders…).
I used the basic idea used in this file:
http://www.blendpolis.de/download/file.php?id=58119
(pressing Q and 1 will save the property, pressing W and 2 will load the property [the prop in the game can be changed with spacebar]).
The script creates a .bgeconf textfile [relativ to the .blend] which SHOULD hold the highscore.

It works pretty fine, the problem though is, that the textfile that this script creates actually doesn’t save the property. It always saves “0”.

In conclusion: as long as you don’t quit Blender, the script works just fine (for whatever reason…?).
But as soon as you quit Blender and reopen it the highscore is lost - and THIS shouldnt happen!

I’m not very good in describing problem, it would be nice if you would make yourself a picture of this problem…
Please note: I’ve got no Python knowledge. Therefore I’m already overwhelmed by these very few lines of script.

Thanks in advance!

Your file works as it should.
Why do you think it saves zero?

when loading the property is set to 3. Wich is not that obvious unless you change it before you start the BGE again.

  • Not really.
    “3” is the default value.
    It can be changed with the spacebar.
    Then you can save the changed value with Q and 1.
    Then you quit and reopen Blender (and the blendfile).
    Now press W and 2 and it SHOULD load the modified property value - which it doesnt because the external saved textfile is all messed up.

I hope you guys now know what I mean…

I tested with BGE 2.57b and it works
1Q: 3
Space: 4
Space:5
Space:6
W2: 3

The most important step is that you quit Blender after pressing 1Q.

Try something like this:

Space: 4
Space: 5
Space: 6
1Q: 6 (saving process)
Quit Blender
Open Blender (same file)
W2: 3 (loading process) <-- WRONG, it should be 6, not 3.

The textfile is called ???.bgeconf btw…

Sure I stopped the BGE multiple times too. All the time it worked it loaded the last saved value.

What version are you using?
Do you have errors in the console window?

Strange…
I tested it with multiple builds (and an exported game runtime) - they all failed.
As soon as I stop the bge or restart Blender all the data is lost…

The save-textfile I get is called “Save_Load.bgeconf”, but it always has the follwoing content:

“{0” (without “”)

…mhh…
Is there any alternative to actually permanently save (and later load) a integer-property in an external txt-file?

I got “{0” first when I faild to follow the instructions and pressed Q1 instead of 1Q - that’s logic cause {0 is probably an empty dict.

Else it works for me to. Ubuntu 11.04, blender 2.58.1

ähmmm. The save actuator saves binary data. All you should see is the string “Cube” inside some binary.

Yes - when I actually set GlobalDict to something before save (press 1). But when GlobalDict is empty is saves {0 - witch may be binary data that just by chance is printable - but probably meaning ‘empty dict’ just as well :slight_smile:

I do not know the binary representation of a dict. I’m pretty sure that I do not need to know that ;).

I think there must be an error in the onsole when trying to read “Cube” from global dict, as it wasn’t loaded from file the must be an KeyError. Finally this means that the property can’t be overwritten.

Ok, I think I must’ve done something in the wrong order - however, it seems to work (at least for my needs) now.
As usual, thanks for the help anyways.