using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # Define our main script structure tagged_lights_puzzle := class(creative_device): # 1. References to Button Devices placed in the level. # Wire these up in the UEFN editor Content Browser properties panel. @editable Button1 : button_device = button_device{} @editable Button2 : button_device = button_device{} # 2. The "Remote Controls" for our subscriptions. # We store these here so we can cancel them later. # Think of these as the "mute buttons" for each input. var ButtonSubscriptions : []cancelable = array{} # 3. The "State" of our puzzle. # False = Puzzle is active. True = Puzzle is solved. var IsSolved : logic = false # This function runs when the script starts. OnBegin() : void = # Subscribe to both buttons' interaction events. SubscribeToButtons() # Function to set up the listening. SubscribeToButtons() : void = # Subscribe to each button's InteractedWithEvent. # Subscribe() accepts a handler function and returns a cancelable handle. Handle1 := Button1.InteractedWithEvent.Subscribe(HandleButtonPress) Handle2 := Button2.InteractedWithEvent.Subscribe(HandleButtonPress) # Store both handles so we can cancel them when the puzzle is solved. set ButtonSubscriptions = array{Handle1, Handle2} # This function is called EVERY time either button is clicked. HandleButtonPress(Agent : agent) : void = # CHECK: Is the puzzle already solved? if (IsSolved = true): # If yes, ignore the click. Do nothing. return # --- PUZZLE LOGIC GOES HERE --- # For this example, clicking either button solves the puzzle immediately. # In a real puzzle, you'd check combinations here. Print("Puzzle Solved! Locking buttons...") # 1. Update State. set IsSolved = true # 2. Trigger the "Win" condition (e.g., spawn loot, change light color). # Here we just log it, but you'd trigger your item granter or prop mover. Print("Loot spawned! (Simulated)") # 3. UNSUBSCRIBE: Cancel every stored event handle. # This is the magic step. We loop through all saved handles # and tell each one to stop listening. for (Handle : ButtonSubscriptions): Handle.Cancel() Print("All buttons unsubscribed. No more clicks allowed.")