Button Combo Lock Puzzle
Button Combo Lock
A press-the-buttons-in-order puzzle. Correct sequence fires a trigger; any wrong press resets progress.
Original, compile-verified Verse by Bizanator (Biloxi Studios). Clean-room sample you can drop into a UEFN project and adapt.
# Button Combo Lock — Biloxi Studios Inc.
#
# A "press the buttons in the right order" puzzle. Players press a set of buttons;
# if they enter the correct sequence, a trigger fires (open a door, spawn loot,
# etc.). Any wrong press resets their progress. Each button knows its own id via a
# small per-button handler object.
#
# Teaches: per-button handler objects carrying state, tracking ordered progress in
# a single index, comparing against a configurable solution, resetting on error,
# and firing a trigger on success.
#
# Setup:
# * Buttons holds the button_device(s).
# * Solution lists the button INDICES (into Buttons) in the required press order,
# e.g. array{2, 0, 1} means "press button 2, then 0, then 1".
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
log_button_combo_lock := class(log_channel){}
# One per button; remembers which button index it represents.
combo_button_handler := class():
ButtonId : int
Lock : button_combo_lock
OnPressed(Player : agent) : void =
Lock.OnButtonPressed(ButtonId)
button_combo_lock := class<concrete>(creative_device):
Logger : log = log{Channel := log_button_combo_lock}
@editable
Buttons : []button_device = array{}
# The required press order, as indices into Buttons.
@editable
Solution : []int = array{0, 1, 2}
# Fired once the full solution is entered correctly.
@editable
SolvedTrigger : trigger_device = trigger_device{}
# How many correct presses the players have entered so far.
var Progress : int = 0
# True once solved, so further presses are ignored.
var Solved : logic = false
OnBegin<override>()<suspends> : void =
for (Index -> Button : Buttons):
Handler := combo_button_handler{ButtonId := Index, Lock := Self}
Button.InteractedWithEvent.Subscribe(Handler.OnPressed)
# Called by a button handler when its button is pressed.
OnButtonPressed(ButtonId : int) : void =
if (Solved?):
return
if (Expected := Solution[Progress], Expected = ButtonId):
# Correct next press.
set Progress += 1
Logger.Print("Correct press {Progress}/{Solution.Length}.")
if (Progress >= Solution.Length):
OnSolved()
else:
# Wrong press — start over.
if (Progress > 0):
Logger.Print("Wrong press — combo reset.")
set Progress = 0
OnSolved<private>() : void =
set Solved = true
Logger.Print("Combo lock solved!")
SolvedTrigger.Trigger()