# This is a Verse Script. Think of it as the "Brain" attached to a device. # We import the necessary tools from Fortnite's library. using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /Verse.org/Native } # This is our "Device" class. It's like a template for our specific button. # In the Scene Graph, this script will live on the Button entity. RevengeButton := class(creative_device): # This is a "Variable". It's a container for data. # Here, it holds a reference to the Button device we placed in the editor. # We will connect this in the UEFN editor by selecting the device in the # Verse Device's property panel. # button_device is the real Verse type for a placeable Button device. @editable MyButton : button_device = button_device{} # This holds a reference to the Timer device we placed. # timer_device is the real Verse type for a placeable Timer device. @editable MyTimer : timer_device = timer_device{} # This is a "Function". It's a set of instructions. # The name "OnBegin" is special. It runs once when the island starts. OnBegin() : void = # We tell the script to listen for the Button being activated. # InteractedWithEvent is the real listenable event on button_device. # Subscribe registers a callback that fires every time the event occurs. MyButton.InteractedWithEvent.Subscribe(HandlePress) # Suspend forever so our subscriptions stay alive for the whole session. loop: Sleep(Infinity) # This function runs whenever the button is pressed. # button_device.InteractedWithEvent passes the interacting agent, so we # accept a ?agent parameter here (it can be false if no agent is found). HandlePress(Source : ?agent) : void = # Source is the agent (player) who pressed the button. # We want to start the Timer device so its countdown begins. # Reset() rewinds the timer to its configured duration, # then Start() begins the countdown. MyTimer.Reset() MyTimer.Start() # No extra code is needed to trigger the Item Granter here because we # wired the Timer's Output Channel to the Item Granter's Channel in the # editor. When the timer expires it broadcasts on that channel and the # Item Granter reacts automatically. # This is the power of Devices: they talk to each other without code.