# This is our main script. It defines the behavior of our puzzle. # Think of this as the "Game Rules" document for this specific puzzle. using { /Fortnite.com/Devices } using { /Verse.org/Simulation } # This is our Prefab type. It represents one light/switch unit. # We use this to tell Verse: "Hey, these lights belong together." type LightUnit is data { # A reference to the light device in the scene graph. # This is like pointing to a specific folder in your inventory. LightDevice: light_device # A reference to the button that controls it. ButtonDevice: button_device # The current state: true = ON, false = OFF. # This is our variable! It changes every time someone clicks. IsOn: bool = false } # This is the main controller. It holds a list of all our LightUnits. # Imagine this is the "Master Control Panel" for your vault. type PuzzleController is data { # A list of all the light switches in this puzzle. # We use a list because we might have 3 lights, or 10. Lights: list = list{} # This is the reward! An item granter that gives the loot. RewardItem: item_granter_device } # This is the "Brain" of our operation. # It runs when the puzzle starts. on_begin() = ( # We need to find all our LightUnits in the Scene Graph. # This loops through every entity in our group. for unit : Scene.GetEntities() { # Add each found unit to our master list. Lights = append(Lights, unit) # Connect the button to our logic. # When the button is pressed, run the ToggleLight function. unit.ButtonDevice.OnButtonPressed += func(): void { ToggleLight(unit) } } ) # This function handles the logic for a single button press. # It’s like a mini-program inside the main program. ToggleLight = func(unit: LightUnit) { # Flip the state: if it was true, make it false, and vice versa. # This is the core mechanic! unit.IsOn = not unit.IsOn # Update the visual light. # If IsOn is true, turn the light on. If false, turn it off. if (unit.IsOn) { unit.LightDevice.SetLightOn(true) } else { unit.LightDevice.SetLightOn(false) } # Check if the puzzle is solved! CheckWinCondition() } # This function checks if ALL lights are currently ON. CheckWinCondition = func() { # Assume we haven't won yet. all_on: bool = true # Look at every light in our list. for unit : Lights { # If even ONE light is off, we can't win. if (not unit.IsOn) { all_on = false break # Stop checking immediately, no need to keep going. } } # If we got here and all_on is still true, everyone is lit up! if (all_on) { # Give the player the reward. # This spawns the item in the player's inventory. RewardItem.GrantItem() # Optional: You could also play a sound or open a door here. } }