Is it possible to make a list of numeral combinations that would activate a scene? I know, I know. Let me explain:
Take a look at this image:

Notice the numbers? Each number corresponds with a switch. The right four switches combined will activate the next scene, while any other four switches combined will activate the restart scene. You follow? Ok, if I was to press say 7-6-3-5 the following scene will activate, but if I press 7-6-3-1 the restart screen will appear. So what I’m asking is, how do I make a list, with python, of 4 numeral combinations that will activate said scene? Or is this not possible? I could probably achieve this with logics, but I’m trying to go with a much easier method.
You could do it with logic bricks. Let me know if this makes sense to you.
-
Make a control object with a boolean prop for each switch. switch1=false, switch2=false, etc.
-
Give the control object a property actuator for each switch property, that sets it to true.
-
Give the control object a property sensor for each switch property, that checks if the property is true. Prop:switch1 Value:True, and so on for each switch property.
-
select the control object and a switch. You can now link logic bricks between the 2.
Link whatever sensor triggers the switch to the the corresponding actuator on the control object:
Sensor(on switch 1)------------>and---------->Property actuator: prop:switch1 = true
- Now decide what to do with the switch combinations. On the control object, connect your property sensors like this:
prop:switch7------------->and--------------->scene: restart
prop:switch6------------->
prop:switch3------------->
prop:switch1------------->
If the switches are all set to true, then the scene will restart. You can reuse each property sensor, so just make a new AND controller for each combination, link the property sensors, and make a new actuator(set scene, end game, whatever.)
Lots of interlinked logic bricks can get messy and confusing pretty fast. If you have more switches or a lot of combinations, I’d use a global python list. If you know how to use python, let me know and I’ll write up that version.
Well, yeah. That was the setup I was going to use, but as you’ve stated also the logic tree would be very confusing. See only that one combination will work to activate the scene, while all others will cause the restart screen to appear. That’s why I was looking for a python solution.
Here’s how i would do it in python:
Create a global switch list. There are 8 items for seven keys. Ignore the first value, so g.switchList[1] = key 1, etc. 0 means the switch is off. You’ll have to add the code for the scene actuator and stuff.
import GameLogic as g
g.switchList = [0,0,0,0,0,0,0,0]
if g.switchList[7] and g.switchList[6] and g.switchList[3] and g.switchList[1] == 1:
#do the restart screen stuff
Create a script that can go on each switch, and changes the global list item for that switch.
#give each switch a property called switch, with the value being the switch number.
import GameLogic as g
cont = g.getCurrentController()
own = cont.getOwner()
sensor = cont.getSensor("sensor") # the sensor that triggers the switch being selected
if sensor.isPositive():
g.switchList[own.switch] = 1
I’m sorry, but I have no idea how to use the script.