Ok, try this, or something like it.
First thing I fixed was I made it unnecessarily complicated by using numbers for counter names and letters for the script. Change that to counter_a, counter_b, counter_c, counter_d.
Second thing I did to make it more complicated was trying to match the variables to the order of the button presses and match that to the counters. All I really needed to do was put the buttons and variables in the same order first to last and you can make your puzzle by putting in different order on the wall.
In summary just have button_a increment counter_a and call the script, button_b increment counter_b and call the script, button_c increment counter_c and call the script and finally button_d increment counter_d and call the script. Have each counter initial setting to 0. You do not need to connect the counters to anything they are just place holders. Put the buttons on the wall in any order you want, but the door will only open if the are pressed in order a, b, c, d. If they are pressed out of order the spawner will lite em up.
This code has not been tested but it should work. I may find a place to use it in my dungeon.
Code: Select all
-- combination lock
function comboLock()
-- set local variables
local a = counter_a:getValue()
local b = counter_b:getValue()
local c = counter_c:getValue()
local d = counter_d:getValue()
-- check for proper press sequence
-- start with first button in sequence and work to last
if a == 1 then
if b == 1 then
if c == 1 then
if d == 1 then
hallwayExitDoor:open()
end
elseif d ~= 0 or c > 1 then
spawner_1:activate()
counter_a:reset()
counter_b:reset()
counter_c:reset()
counter_d:reset()
end
elseif c ~= 0 or d ~= 0 or b > 1 then
spawner_1:activate()
counter_a:reset()
counter_b:reset()
counter_c:reset()
counter_d:reset()
end
elseif b ~= 0 or c ~= 0 or d ~= 0 or a > 1 then
spawner_1:activate()
counter_a:reset()
counter_b:reset()
counter_c:reset()
counter_d:reset()
end
end
I took the time to flow chart this one out so I feel pretty good about it.
Hope this helps.