# This is a simple Verse script for a respawnable coin # We define the 'Coin' as an object that has a Timer and a Respawn function # First, we need to import the tools we need using { /Fortnite.com/Devices } using { /Verse.org/Simulation } # This is our main 'Actor' (think of it as the Coin's brain) # creative_device is the real base class for UEFN Verse devices respawnable_coin := class(creative_device): # These are our 'Variables' - things that can change # A variable is like a loot box: it holds an item, and you can swap the item inside. # These @editable fields appear as slots in the UEFN details panel, # where you drag in your real Timer and Coin devices from the scene. @editable TimerDevice : timer_device = timer_device{} @editable CoinDevice : item_spawner_device = item_spawner_device{} # This is the 'Event' that runs when the game starts # OnBegin is the real UEFN lifecycle function; it is async because it can Await OnBegin() : void = # Here we 'Bind' the devices together in code. # Subscribe() is how Verse attaches a callback to a listenable event. # We tell the CoinDevice: "When you are collected, run StartTimerOnCollect." CoinDevice.ItemPickedUpEvent.Subscribe(StartTimerOnCollect) # We tell the TimerDevice: "When you finish counting, run RespawnCoin." TimerDevice.SuccessEvent.Subscribe(RespawnCoin) # Called whenever any agent collects the coin; we ignore the agent and start the timer. StartTimerOnCollect(Agent : agent) : void = TimerDevice.Start() # Called when the timer reaches zero; respawn the coin for every player. RespawnCoin(Agent : ?agent) : void = # Enable() re-enables the item_spawner_device so all players can collect it again. # note: item_spawner_device inherits Enable() from base_item_spawner_device to # restore visibility/collectibility; Reset() is not available on this device. CoinDevice.Enable() # To use this, place this device in the scene from the Content Browser, # then drag your Timer and Coin devices into the 'Timer Device' and 'Coin Device' slots # in the UEFN details panel.