Here is the example I went over on the live onboarding:
using { /Fortnite.com/Devices }
using { /Verse.org/Native }
using { /EpicGames.com/Temporary/Diagnostics }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
log_new_device:=class(log_channel){}
# This is a new Verse based class that is used with the ScriptDevice in UEFN
#
# Getting started: <link to UEFN docs>
light_toggler := class<concrete>(creative_device):
Logger:log = log{Channel:=log_new_device}
@editable
MyLightBulb:customizable_light_device := customizable_light_device{}
@editable
MyLightButton:button_device := button_device {}
var ButtonSubscription:?cancellable := false
var IsLightOn:logic = false
var NumInteractsBeforeBreak:int = 3
# Runs when this device_script is started in a running game
OnBegin<override>()<suspends>:void=
# Replace this with your code
Logger.Print("Verse device started!")
set ButtonSubscription = option { MyLightButton.InteractedWithEvent.Subscribe(HandleMyButtonInteract) }
HandleMyButtonInteract(MyPlayer:player):void=
set NumInteractsBeforeBreak = NumInteractsBeforeBreak - 1
if (NumInteractsBeforeBreak = 0):
if (ButtonSub := ButtonSubscription?):
Logger.Print("Button Broke, number of Interacts Left was: {NumInteractsBeforeBreak}")
ButtonSub.Cancel()
MyLightButton.Disable()
spawn { PulseLight() }
ToggleLight()
ToggleLight():void=
if (IsLightOn = true):
MyLightBulb.TurnOff()
set IsLightOn = false
else if (IsLightOn = false):
MyLightBulb.TurnOn()
set IsLightOn = true
PulseLight()<suspends>:void=
randomFloat:float = GetRandomFloat(0.2, 0.7)
Logger.Print("Sleeping for: {randomFloat}" )
Sleep(randomFloat)
ToggleLight()
spawn { PulseLight() }
<#
# Runs when this device_script is stopped or the game ends
OnEnd<override>():void=
# Uncomment this function, then replace this with your code
Log("Verse device stopped!")
#>