1
$\begingroup$

For example, imagine a game where you collect objects (like coins, gems, keys, etc.), and the ones you pick disappear like they do in any other game where you collect coins. So, you are in level "A", you collected some coins, then you go to level "B", and when you decide to go back to level "A" the coins you collected in that level never appear again because you already have them, but the ones you didn´t collect are still there. How can I do this?

I already know how to use the "edit object" actuator with "end object", as well as "set scene" to change levels, but when I do that, the already collected objects always appear again when I go to the second level and go back to the first, and that´s not what I want.

Python is preferred, but I dont mind using the logic bricks.

$\endgroup$
0
$\begingroup$

I assume with "level" you mean scene.

When you switch scenes, you destroy the current one and load a new one. The new scene will be as it is loaded from file. It will not know anything about the previous scene.

When you keep game status (such as points) in a scene it will die with the scene.

Solutions

Keep scene

Do not switch scene to preserve the game status.

Nether return

When leaving the scene you never come back. Therefore you do not need to know what was collected in previous scenes.

Keep game status separate

By keeping the game status somewhere else (e.g. at a Python module, or an overlay scene) it will survive a scene switch.

Transfer game status

Some game status are better kept in the scene (e.g. status of doors, collected objects, moved objects). Such things are typically needed when loading the scene again at a later stage (it is not the same scene, it is a new scene loaded from same source).

You need a store/restore system.

It basically extracts the game state (or part of it) from the scene and places it in a storage outside of the scene (e.g. a python module).

At a later stage the game state can be reapplied from storage to the same or a different scene. This can happen after a scene change.

You often find such a system in conjunction with a save/load system. I suggest to search for such a system as it would be way to much within this answer.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.