I’d like to be able to suspend & resume a particular scene without using logic bricks, however the only documentation that I’ve been able to find anywhere on how to do this isn’t particularly useful (to me) since is has no usage examples and seems to be written in some kind of esoteric shorthand:
scene = bge.logic.getCurrentScene()
if Condition:
scene.suspend()
else:
scene.resume()
By the way, what is the purpose of the dict entry? I’m kinda confused by it. You can check if a scene is paused with scene.suspended – it returns true if it’s paused, false if it’s not. Might come in handy.
The GD is there for easy acces trough out the blend file, and if needed to save it.
Here is one with the use of a GD
scene = bge.logic.getCurrentScene()
GD = logic.globalDict['paused']
if not GD:
print('no GD[paused] found')
return
if ESCKEY and GD:
scene.suspend()
else:
scene.resume()
dont use the GD. what if you open a new blend while the game is paused? you will have to keep track of the variable yourself, instead of the garbage collector.
i personally think this GD method is cleaner.
ESCKEY = bge.logic.keyboard.events[bge.events.ESCKEY]
if ESCKEY == 1: # only process pause on key press
paused = GD.get("Paused", False)
if paused ==True:
scene.resume()
GD["Paused"] = False
else:
scene.suspend()
GD["Paused"] = True
Also be careful because suspending a scene from inside itself stops further logic inside the suspended scene, so you will be able to pause it, but not resume it.
Unless you add a second scene and trigger logic from there.