Save and load

_Hello! I’m trying to make a system, to save and load the game, I found these SixDayStudio tutorials:


I modified the script so that I could use the mouse.
The original script is in the text editor.

NOTE: Despite my efforts to learn, I still do not know how to program what I do is modify and inxertar, with parts of others, to try to find a solution.

_With these tutorials, I managed to save and load the game, but only within the stage itself.

What I want is to load the saved point directly from the menu by clicking the “LOAD” button.

Example: Save the game in phase 2, exit the game, click “LOAD” to go straight to the point saved in phase 2.

_If anyone can help me by changing the script for this purpose or have another way to do it, thank you.

Below is a very simple .blend file with what I’ve done:

https://drive.google.com/file/d/13Xp3PDZXMCoNszP3CD8rbLaKGIY04jc0/view?usp=sharing

What I want is to load the saved point directly from the menu by clicking the “LOAD” button.

you see what he does there to load. what you need to do is make a button in the menu, sensor->python (module mode) and enter the scriptname.loadGame

now if you press the button the loadGame action gets called and executed.

No idea what you want to save, but that save/load need alot of options and checks more if you want to save added objects as well.
you can find a working save/load in my signature.

_ I did what he said, but it did not work, I know it’s probably my fault, but as I said, I do not know how to program it. If you can tell me what I did wrong and how do I do it right, I thank you.

Picture:

https://drive.google.com/file/d/1Iph7TEHj-B7IdXx782RrYNDz4Qx5tC5N/view?usp=sharing

https://drive.google.com/file/d/1Iph7TEHj-B7IdXx782RrYNDz4Qx5tC5N/view?usp=sharing

ok 3 scenes and a menu scene

in this case you need to define the scene that needs saving and loading, i assume…, the tutorial is only about saving some info from the main scene(where the script runs from).

so what you need is keeping track of what scene is open and save that data, and load it when you need it. So you need to have a property(or anything) that tracks the opened scenes, then you need to use that info/property to save and or load the data from the opened scenes. Also when you load it you need to check/set the right scenes else you keep ending up in scene_1 or only with errors when you load your game.

This is not an easy task if you do not now python.

I strongly suggest to avoid saving directly from the button. The button is UI only, while saving is business logic. Saving should work without UI.

What you can do is to let your button send a message e.g. “save now”.

On the scene you want to save have one object that is listening to subject “save now”. When it receives such a message it triggers the save script. This way you still can save the current scene (typically you do not want to save the menu scene).

Due to the separating of UI and business you can now perform saving whenever you want, e.g. when reaching checkpoints, pressing a key, leaving the game … . You just send the message “save now”.

The same on loading. Start loading when receiving a message “load now”. You can even do that in multiple phases. Phase 1: add scene, Phase 2: load data and manipulate the scene.

_ I may be wrong, but it seems to me that they did not see the file, .blend I posted. The file is a small sample game, which has the menu and 3 scenes, in each scene has 3 buttons: Save; Exit and Load, these buttons work perfectly within each scene, each scene has an empty, responsible for executing the script, but I want to access Save through the menu load button. Look at the .blend file I posted.

https://drive.google.com/file/d/13Xp...ew?usp=sharing

Your button logic (at the level scene) can benefit from a different design.

Typically you wait for two events:

  • A) click
  • B) mouse over a button

When A) and B) are just evaluated at the the same time your want to run the according operation.

I suggest to either react on just clicked or just released. Currently your code tries to save or load every frame you hold the mouse button. I would not expect this code at the object “Empty” either as I assume this is responsible for loading and saving. Dealing with buttons is too much overhead.

When you use the method I suggested in post#5 (message) you can setup two separate logic paths in Empty:

  • message sensor --> Python load
  • message sensor --> Python save

Basically you this logic is only interested that it should load or save. It does not care that part of the game is asking for that operations. In other words: The save/load logic does not care what button was pressed and how strong it was pressed.

It simplifies the button logic and it simplifies the save/load logic too.

_Excuse friends for the delay, but I’m still trying to implement what they told me, as soon as I finish I give an answer.

_Friends unfortunately I could not, "I’m giving up for now.

Does anyone know of a Python course exclusively for Blender (BGE)?

You can start reading a bit there: https://docs.blender.org/api/blender_python_api_current/bge.logic.html

Its a bit silly, but reading once this page might give you ideas about what could be possible to do, because you’ll see the functions available in the bge.logic module, and you will see their purpose too. Just look for a “these functions will help me in the future, its cool !” feeling when reading a bit. Even if you don’t understand 100%, its for getting a feel about what seem possible using this module.

Then just try to write scripts to test basic ideas. Search the documentation for anything you would need.
Its rough but it works.

_WKnight02, Thank you, I will download the entire API.

You can search on youtube for tutorials, there are plenty of them.
https://www.youtube.com/results?search_query=blender+bge+python+tutorial

#edit, oops this is not for bge but blender outside the bge, sorry.
https://cgcookie.com/course/introduction-to-python-scripting

_Thanks Cotaks, I’ll search and see if I can find one that is easy to understand. Hug!