Hi. I’m wondering how can i access the property of an object and save it to the text file. Of course I want to load it back when i want it.
pls clear up,
- you want to save load somthing ??
2 you want to change the obj[‘Text’] ??
i have already implemented the position and rotation of the objects. i want to save player health and the else variables like ammo and so on… i want to access the property of object “Default” which is the player and get value of property “Health” and save it to text file. When loading the game i want to to load the value of the “Health” property and reset it… it!s now clear?
try the SaveLoader
So you’re really asking how to access a property’s value. Here’s a code example that gets the property “Prop” from the object the script is applied to and saves it to the variable prop.
cont = GameLogic.getCurrentController() obj = cont.owner prop = obj["Prop"]
You said you have already saved position and rotation, so you can just save the variable prop just like you saved the position and rotation.
Now to set a property, you can do this:
cont = GameLogic.getCurrentController() obj = cont.owner prop = Put your way of opening saved variable here obj["Prop"] = prop
When loading, you’ll have to make sure it only opens it once, or you won’t be able to change the property, because it will keep loading. Here’s what I do to fix that.
I first add a boolean property named “loaded” set to False. Then i add this code onto any script that always runs.
cont = GameLogic.getCurrentController() obj = cont.owner if obj["loaded"] == False: Put whatever things you want to run only once here, such as the loading obj["loaded"] = True
I’m now implemented the Monster’s saveload script but…
i have the switchable torch in my game and i want to remember the state of the torch when i’m saving the game… it will remember the state but after i load the game I’m not able to switch the torch back off or on… i’m using the ipo animation to do this and the “torch” boolean property to get the torch state… it’s working but not after i save or load the game…
As I wrote in the other thread, could you provide me with a blend including the torch and the sav/load logic? That would help me a lot
my blend have about 90 mb i will send you a message with link to my dropbox…
Here is a nice tutorial on Save/Load data with GlobalDict for the Gtown Game, from Oldjim.
But I haven’t started the tutorial description but you can download the example file.