SaveLoader 2.7

It works fine thank it’s cool men nice work
:spin:

The script is great! It works perfectly in the example, however in my game it works only the first time the game is run ( it’s saving and loading like it should) - but if I close it, the save file won’t load again. I appended all the empties and the save file is generated like it should. Any ideas what I’m doing wrong?

Nice work man… Thanks so much

Great stuff, however when i load the save everything goes wild.
The camera goes of the map, the weapon spins …etc
Any help ??

Be aware that restoring position/orientation/ scale of animated objects is in conflict when these elements are controlled otherwise. E.g by an action or by Python code.

In this case you need to exclude these elements from beeing restored. I think I mention this earlier in this thread.

Example: you open a sliding door with an action: the open door position is stored.
After restore the door will be placed at the open position, but the action thinks it is at the closed position. Which means when playing the action, the door opens even further.
Solution skip restoreing the position, play the action in property mode and restore the action.

Hmm… While thinking of this, I remember this issue is there because at the time of writing the SaveLoader the setting of the current frame of the action actuator was ignored. I have to check if that is still the case. Indeed there are a view more elements to store right now.

Cheers for reply monster, yeah soon as the scene loads back up
the player flys off map and camera goes some where else lol.
Hopefully i can find a solution soon, if you want me to make
a video of what happens i can :slight_smile:

^^Bump please^^

I just recognized the current frame of the action actuator gets stored/restored already. It is that bge 2.49 simply ignores that.

So it is working.

Anyway. The conflicts are still there. You need to exclude restore any transformation that is set by the ActionActuator. E.g. if the Actuator plays a positional action. You need to exclude “position” from been restored. You do that by adding a property “saveLoad.exclude” with value “position”.

Edit:
I suggest you open a new thread, download a simplified blend (simple meshes, no textures) and I look at it.

Hi mate can you explain it clearly for nobel like me?
I made a simple example to test it, an action from 1 till frame 80.
I place a “Property” ActionActuator, add a Property (“CurrentFrame” for example), set value into a middle of the action (frame 40) and assigned it at “Property” case in the actuator. Guess I no understand the goal of this type of actuator, the action goes direct to the assigned frame, but nothing more happens (not continue the action).

Since 2.62 the ActionActuator in property mode needs to be activated each time the property changes. Earlier versions kept the actuator activated all the time even if the property did not change = wasting time.

I suggest to use a Property Sensor [True Pulse] in changed mode to activate the ActionActuator. (If you are sure the property changes all the time, you can trigger with the same event that causes the property change e.g. always sensor.)
When the SaveLoader restores the property the sensor will sense the change and activate the actuator to play the restored key frame (pose). The SaveLoader can not activate any actuator!

Example:
you have the setup:
property frame: 0.0
with
Event to play the action [True pulse]
–> AND
----> Property Add “frame” “24/60” (this sets the next keyframe)
----> ActionActuator Property “frame”

t(0):
The scene gets loaded. “frame” is 0.0 the actuators are deactivated
t(1)
The logic of the first frame takes place.
The property actuator changes “frame” to 0.4.
The ActionActuator play key frame 0.4
t(2)
The property actuator changes “frame” to 0.8.
The ActionActuator play key frame 0.8

at any later time you restore the property “frame” to lets say 16.8


The property “frame” gets set to 16.8 by the saveLoader.
The ActionActuator is not activated by the saveLoder (that is impossible).
t(r+1)
If the ActionActuator gets activated, it will play frame 16.8. Otherwise not.
The important point is: The event to activate the action actuator must exist.

I hope that makes any sense to you.

Thanks for the big explain, but I still have same dudes …

Since 2.62 the ActionActuator in property mode needs to be activated each time the property changes. Earlier versions kept the actuator activated all the time even if the property did not change = wasting time.

Ok, the action dont works but anyway the logic have a “always” running. wasting resources …

----> Property Add “frame” “24/60” (this sets the next keyframe)

Why you explain it “24/60” instead “0.4” value directly? Or are you meaning each 60 frames or something like this…

For example, the animation is since frame “1” till “80”, I set the property frame at “40”. I’ve checked trying your pourpose and check than tha animation start right in that frame, 40. But It has a always sensor, although the animation has last keyframe in the frame “80”, it doesn’t keep running? like ghost frames?

The ActionActuator is not activated by the saveLoder (that is impossible).

You mean at you way/script mechanic, isn’t it?..

Before of your idea I tried by the method object.playAction


def SaveParty():  
    for object in objects: 
        if type(object) == bge.types.KX_GameObject: 
            ...        
            propsInObj = object.getPropertyNames()    
            if len(propsInObj) > 0: #if the object has properties
                ...
                for property in propsInObj: #recorremos una a una las propiedades
                    bge.logic.globalDict["properties"][str(object)][property] = object[property]
                    for actuator in object.actuators:
                        if isinstance(actuator, BL_ActionActuator): #if has a Actuator Action
                            if object.isPlayingAction(): #if is running a Action during the save
                                bge.logic.globalDict["frame"][str(object)] = {}
                                bge.logic.globalDict["frame"][str(object)] = object.getActionFrame()
                        else: #if not just save the position and orientation
                                bge.logic.globalDict["position"][str(object)] = {}
                                bge.logic.globalDict["position"][str(object)] = list(object.worldPosition)
                            
                                bge.logic.globalDict["orientation"][str(object)] = {}
                                bge.logic.globalDict["orientation"][str(object)] = list(object.worldOrientation[0]),list(object.worldOrientation[1]),list(object.worldOrientation[2])

    bge.logic.saveGlobalDict()


def LoadParty():       
    for object in objects:
        if type(object) == bge.types.KX_GameObject: #si es objeto fisico (no luces, etc...
            ...                
            propsInObj = object.getPropertyNames()       
            if len(propsInObj) > 0: #si tiene propiedad/es el objeto entra en juego..            
                for property in propsInObj:                                                 
                    object[property] = bge.logic.globalDict["properties"][str(object)][property]
                    for actuator in object.actuators:
                        if isinstance(actuator, BL_ActionActuator):
                            if str(object) in bge.logic.globalDict["frame"]:
                                initFrame = float(bge.logic.globalDict["frame"][str(object)])
                                endFrame = object["lastFrame"]
                                object.playAction(actuator.action, initFrame, endFrame, layer=0, play_mode=bge.logic.KX_ACTION_MODE_PLAY)
                            else:
                                object.worldPosition = tuple(bge.logic.globalDict["position"][str(object)])
                                object.worldOrientation = tuple(bge.logic.globalDict["orientation"][str(object)])

With the always the Action should play. As a first step I suggest to enable debug on the property that it still changes after restore. If the action still does not play it might be a(nother) bug in the ActionActuator -> Bugtracker.

I write 24/60 because you might run with different frame rates. 24 (animation fps) and 60 (game fps) is pretty easy to guess ;).

object.playAction cannot be stored/restored by the save loader. Here you need to adjust your own code to do store/restore. Unfortunately I can’t offer you an easy hook to the saveLoader. I never though of that option.

Last question, this system loader is not able to combine property actionActuator with reversed animation, like flipper like you explain me in other thread?

About the frames is dude it because I don’t know if is with sense or not but 0.4 = 24/60

Respect third paragraph is normal, each case has different requirements, I have solved for my purpose by python.

Thank you for everything, you are very kind and example in any forum. You shoul put your PayPal account to invite people like you sometimes to a beer :beer:

Enviado desde mi HTC One S usando Tapatalk 2

I’m still confused. Will this script work with a menu? I’m trying to wrap my head around if when you load the game it starts at a title screen. From here you can choose a new game or if you’ve saved before to load from first save or the second save slot (depending on where you saved the game). I only want two save slots and don’t want to have “quick saves” like in the demo of hitting “S” or “L”.

Is it possible and how would you set it up with your code?

Sure, it does.

You should try to save/restore the game scene rather than the menu scene as that makes more sense ;).
When using the objects from the demo, I suggest to keep them in the game scene. You can trigger store/restore with a message. The final save/load can be done with objects of the menu scene as they work with the stored data only (which is scene independent).

Okay, so let’s say I make a save point in game. When the character clicks on it.
It puts the scene “menu” in an overlay on top. When they click “save”, send a message to the empty in the current scene that saves the game and removes the “menu” scene.

So how do I tell it to save filename1, filename2, etc?

Can you make it so that it saves added objects? Because when I add objects, or change cameras the game does not save those details into the .bgeconf

is there a way to save that into the data?

You can save added objects (see video tutorial). Just make sure the originals are still in the scene (as inactive objects = hidden layer).

The SaveLoader stores the status of the objects in a dict (globalDict). You can save this dict .bgeconf with the SaveActuator or in any other file with the SaveLoader. The second option allows you to save it as human readable (and editable) text file.

Hello,

This is a wonderful resource, so thank you. In my game, the character hold weapons parented to the arm’s bone.
I made you script work in an inelegant way : first, in my player’s armature, an actuator keyboard=“s” plays the rest pause when the attached object is in it’s right position, then it sends a message to the save loader, it saves, then the animation becomes normal again and the parented objects is still in the right position. The problem is that during 0,5 s the character fixe in rest pose. But it’s an idea, maybe it can give ideas to greater Blenderists !

Donfrappa

Thank you, professor. Your save loader has saved me (I swear that pun wasn’t on purpose) on numerous occasions. I am currently making an RPG and I finished making the character creator which runs mostly using properties, being as it changes the mesh based on which properties are true and false. now im wondering if your save loader can save the properties from scene to scene, and also when you load a save, and if not, how to do so. Thank you.

-Nixodemus1