Actions in Verse
The generated logic file, and how to react to clicks and changes.
The editor writes a second file next to the layout: <wbp>_logic.verse. It is a starting point for your actions,
with one branch per element and a Print in each. Replace the Print lines with your code.
This file is yours
The layout file is written again each time your zones change. The logic file is not: download it once, then edit it freely. When you add an element later, add its branch by hand.
The generated file
using { /Verse.org/SceneGraph }
using { /Verse.org/Simulation }
using { WorldUIKit }
wbp_shop_logic<public> := class<final_super>(component):
var Subscriptions<private>:[]interactive_subscription = array{}
OnBeginSimulation<override>():void =
if (Kit := Entity.GetComponent[interactive_widget_component]):
set Subscriptions = array{Kit.SubscribeClicked(OnClicked), Kit.SubscribeChanged(OnChanged)}
OnEndSimulation<override>():void =
for (Subscription : Subscriptions):
Subscription.Cancel()
set Subscriptions = array{}
# A button clicked by Event.Player.
OnClicked(Event:interactive_event):void =
case (Event.Element):
"BuyBlade" => Print("BuyBlade clicked")
"BuyShield" => Print("BuyShield clicked")
_ => {}
# A toggle switched (Event.On), a choice or a tab selected, a slider moved (Event.Value, by its steppers too).
OnChanged(Event:interactive_event):void =
case (Event.Element):
"Items" => Print("Items selected")
"Music" => if (Event.On?) then Print("Music on") else Print("Music off")
"Volume" => Print("Volume: {Event.Value}")
_ => {}Add the wbp_shop_logic component to the widget entity, next to interactive_widget_component.
OnClickedreceives the clicks of the buttons.OnChangedreceives the new state of toggles (Event.On), the choice or tab that gets selected, and the value of sliders (Event.Value), while they are dragged and when a stepper moves them. Steppers have no branch of their own: their slider's branch runs.- A widget with only buttons gets only
OnClicked, and one with only states gets onlyOnChanged.
Every event carries the player who clicked (Event.Player) and the component (Event.Widget), so a branch can read
or change any other element. See Verse API.
Examples
Read another element
The Buy button checks which skin the player selected.
OnClicked(Event:interactive_event):void =
Kit := Event.Widget
if (Event.Element = "Buy"):
if (Kit.IsOn["SkinGold", ?Player := option{Event.Player}]):
Print("Buying the gold skin")
else:
Print("Buying the red skin")Unlock an element
SetEnabled turns an element on for everyone. A disabled element can be aimed at but not clicked.
if (Event.Element = "ClaimReward"):
Event.Widget.SetEnabled("SkinGold", true)Open a screen
if (Event.Element = "Settings"):
Event.Widget.SetScreen(2, ?Player := option{Event.Player})Use a device
The logic component is yours: add the device fields you need, and set them in the Details panel.
using { /Fortnite.com/Devices }
wbp_shop_logic<public> := class<final_super>(component):
@editable
BladeGranter:item_granter_device = item_granter_device{}
# ...
OnClicked(Event:interactive_event):void =
if (Event.Element = "BuyBlade"):
BladeGranter.GrantItem(Event.Player)A component starts before the creative devices of the island. The kit's events arrive once the round has started, so devices are ready when your branches run.
Waiting for an event
Instead of subscribing, a component can wait for the kit's events in OnSimulate.
OnSimulate<override>()<suspends>:void =
if (Kit := Entity.GetComponent[interactive_widget_component]):
loop:
Event := Kit.ClickedEvent.Await()
Print("{Event.Element} clicked")With per-player states
When States is PerPlayer, pass ?Player := option{Event.Player} to IsOn, GetValue, GetScreen, SetOn,
SetValue and SetScreen, so they read or change the state of the player who clicked. Without it, SetOn,
SetValue and SetScreen change every player's state (and the state of players who join later), and IsOn,
GetValue and GetScreen read the state new players start with.