Hello, my quiz game has a random set of scenes up to 15 random scenes and I want my game to be finished or stop after answering 15 questions and doesnt repeat the same question scene twice… How can I do that? Please help… Thanks
Somehow this sounds very familiar. I think such a question raised up two time within the last half a year. Nevertheless:
A good way is to use Python (controller).
Create a list with the names of the available scene names.
Shuffle the list (random module).
Before scene switch take the first scene name from the list and remove it from the list too.
Then switch to this scene.
When the list is empty all scenes where shown.
Make sure to store the list in game scope e.g. in globalDict (= can be saved/loaded) or a module.
sample code:
import bge
import random
from bge.logic import getCurrentController
#--- configuration
allSceneNames = [
"Scene.001","Scene.002","Scene.003"
,"Scene.004","Scene.005","Scene.006"
,"Scene.007","Scene.008","Scene.009"
,"Scene.010","Scene.011","Scene.012"
,"Scene.013","Scene.014","Scene.015"
]
#--- internal
storage = bge.logic.globalDict
KEY_TO_AVALIABLE_SCENE_NAMES = "availableScenes"
#--- BGE callable
def createRandomSequence():
if not allSensorsPositive():
return
availableSceneNames = allSceneNames.copy()
random.shuffle(availableSceneNames)
storage[KEY_TO_AVALIABLE_SCENE_NAMES] = availableSceneNames
def setNextScene():
if not allSensorsPositive():
return
availableSceneNames = storage[KEY_TO_AVALIABLE_SCENE_NAMES]
nextSceneName = availableSceneNames.pop()
setSceneAndActivateActuator(nextSceneName)
def isDone():
if not allSensorsPositive():
return
if not len(storage.get(KEY_TO_AVALIABLE_SCENE_NAMES)):
activateAllActuators()
#--- internal
def allSensorsPositive():
for sensor in getCurrentController().sensors:
if not sensor.positive:
return False
return True
def setSceneAndActivateActuator(sceneName):
for actuator in getCurrentController().actuators:
try:
actuator.scene = sceneName
getCurrentController.activate(actuator)
foundActuator = True
except AttributeError:
continue
def activateAllActuators():
for actuator in getCurrentController().actuators:
getCurrentController().activate(actuator)
Store this in a file called scene.py.
On startup (and/or restart) trigger a Python controller in module mode
e.g.
Always (no pulses) -> Python controller scene.createRandomSequence
on scene switch let the Python controller set up the scene actuator:
Sensor -> Python controller scene.setNextScene -> Scene Actuator (set scene mode)
to check if there is a scene left (before you get an error) you can trigger isDone:
Sensor -> Python controller scene.isDone -> Actuator
It will activate the actuators when there is no further scene left.