Hi all,
I propose a similar code that I use in my game...
4 switches allow to open a door with the condition that they are activated in a specific order.
For my game, I used colored blocks (red, green, blue and yellow) with a light system on each switch when activated.
The door automatically opens when the code is correct (in my game, it's a grid that rises like a castle door).
If the order is not correct, a message appears at the door and switches are reset and the lights are switched off.
Principe of the test scripts :
Each switch uses a script called "serrure" from 1 to 4.
The door uses a script called "porte_4serrures".
The code corresponding at the opening sequence is defined in this script with les values of "serrure01, serrure02, serrure03, and serrure04".
example : opening order is 2,4,1,3 : serrure01 = 2 serrure02 = 4 serrure03 = 1 serrure04 = 3
When the player touches a switch, this one is activated.
example :
switch 03 is the 1st activated, the value is : serrure03 = 1
switch 04 is the 2nd activated, the value is : serrure04 = 2
switch 02 is the 3rd activated, the value is : serrure02 = 3
switch 01 is the 4th activated, the value is : serrure01 = 4
When the four switches are activated, the player goes to the door.
A message appears to indicate if the opening sequence of the switches is correct or not.
If the opening order is incorrect, the switches are reset and the player can start again.
The only limitation is the sequence order is fixed in the door script, but it might be enough for what you want to do ?
Be indulgent, it's one of my first code I share...