SsimnJS Docs

Verse API

Events, subscriptions, methods and types of the WorldUIKit module.

Everything is in the WorldUIKit module. From a component on the widget entity, get the kit with GetComponent:

using { /Verse.org/SceneGraph }
using { WorldUIKit }

my_logic<public> := class<final_super>(component):
    OnBeginSimulation<override>():void =
        if (Kit := Entity.GetComponent[interactive_widget_component]):
            Kit.SubscribeClicked(OnClicked)

    OnClicked(Event:interactive_event):void =
        Print("{Event.Element} clicked")

Keep the returned interactive_subscription and call Cancel() on it in OnEndSimulation, as the generated logic file does.

Events

EventPayloadSent when
ClickedEventinteractive_eventEvery click of an enabled element: buttons, toggles, choices, tabs, steppers, and sliders when fire is released.
ChangedEventinteractive_eventA click changes a state: a toggle switches, a choice or tab gets selected, a tab changes the screen, a slider value changes (also while it is dragged).
HoveredEventinteractive_hoverA player's crosshair arrives on an element (Hovered true) or leaves it (Hovered false).
  • When a click changes a state, ChangedEvent is sent before ClickedEvent.
  • A stepper sends ClickedEvent with its own name, and ChangedEvent with the name of the slider it moves. In both, Value is the new value of the slider.
  • States changed from Verse (SetOn, SetValue, SetScreen) send no event.

The events are Verse events: Await() them in a suspends function, or use the subscriptions below.

Subscriptions

SubscribeClicked<public>(Callback:type{_(:interactive_event):void})<transacts>:interactive_subscription
SubscribeChanged<public>(Callback:type{_(:interactive_event):void})<transacts>:interactive_subscription
SubscribeHovered<public>(Callback:type{_(:interactive_hover):void})<transacts>:interactive_subscription

interactive_subscription.Cancel() stops the calls.

Methods

MethodDescription
ElementNames()<transacts>:[]stringNames of the elements, in layout order.
IsOn[Name:string, ?Player:?player]<transacts><decides>:voidSucceeds when the toggle is On, or the choice or tab is selected.
GetValue(Name:string, ?Player:?player)<transacts>:floatValue of a slider (0.0 for an unknown name).
GetScreen(?Player:?player)<transacts>:intThe active screen.
SetOn(Name:string, On:logic, ?Player:?player):voidSwitches a toggle, or selects a choice or tab. A tab turned on opens its screen.
SetValue(Name:string, Value:float, ?Player:?player):voidSets a slider, snapped to its Step.
SetScreen(Screen:int, ?Player:?player):voidOpens a screen and selects the tab that opens it.
SetEnabled(Name:string, Enabled:logic):voidEnables or disables an element, for everyone.
SetPrompt(Name:string, Prompt:string):voidChanges the interact prompt of an element, for everyone. Empty: its name.
WidgetFor(?Player:?player)<transacts>:entityThe widget a player sees: their per-player copy, else the placed widget. Cast it to your WBP's _entity class to write your own fields.

?Player targets one player's state when States is PerPlayer. Without it, the Set methods change every player's state, and the reads return the state new players start with. With Shared states, there is one state and ?Player changes nothing. See Shared and per-player states.

Kit.SetOn("Music", false, ?Player := option{Event.Player})
if (Kit.IsOn["Music", ?Player := option{Event.Player}]):
    Print("Music is on for this player")

Your own fields

The kit writes the fields of the layout (hover, on, value…). To write other fields of your WBP from your logic (gold, a message, a code), get the widget the player sees with WidgetFor and cast it to your WBP's _entity class:

WidgetFor<public>(?Player:?player = false)<transacts>:entity

It returns the player's per-player copy when there is one, else the placed widget (also without ?Player). From the Shop example:

Show(Kit:interactive_widget_component, Who:player, Text:string):void =
    if (W := Widgets.WBP_WorldUIKit_Shop_entity[Kit.WidgetFor(?Player := option{Who})]):
        set W.Gold = GoldOf(Who)
        set W.Message = InteractiveText(Text)

Widgets.WBP_WorldUIKit_Shop_entity is the class of the kit's example; yours is named after your WBP's folder, e.g. Menus.WBP_Shop_entity.

Types

interactive_event

FieldTypeDescription
Widgetinteractive_widget_componentThe component that sent the event.
ElementstringName of the element.
Kindinteractive_kindKind of the element.
PlayerplayerThe player who clicked.
OnlogicToggle, choice, tab: the new state.
ValuefloatSlider: the new value. Stepper: the new value of its slider.
ScreenintThe screen shown to the player after the click.

interactive_hover

FieldTypeDescription
Widgetinteractive_widget_componentThe component.
ElementstringName of the element.
PlayerplayerThe player whose crosshair moved.
Hoveredlogictrue when the crosshair arrives, false when it leaves.

Enums

interactive_kind<public> := enum{Button, Toggle, Choice, Tab, Slider, Stepper}
interactive_scope<public> := enum{Shared, PerPlayer}

Layout and WBP fields

A layout is any component, next to interactive_widget_component, that implements interactive_layout. It can also implement interactive_fields: the kit draws nothing on the widget, it calls these methods so that the WBP shows hover, clicks and states from its own fields. The online editor writes both. Without interactive_fields, the widget works but shows no state, and the kit says so in the log.

interactive_layout_data<public> := struct:
    Width<public>:float = 0.0
    Height<public>:float = 0.0
    Elements<public>:[]interactive_element = array{}

interactive_layout<public> := interface:
    GetLayout<public>()<transacts>:interactive_layout_data

interactive_fields<public> := interface:
    SetHovered<public>(Widget:entity, Element:string, On:logic):void
    SetPressed<public>(Widget:entity, Element:string, On:logic):void
    SetOn<public>(Widget:entity, Element:string, On:logic):void
    # Fraction: 0..1 along the slider. Text: the value as shown to players.
    SetValue<public>(Widget:entity, Element:string, Value:float, Fraction:float, Text:string):void
    SetEnabled<public>(Widget:entity, Element:string, On:logic):void
    SetScreen<public>(Widget:entity, Screen:int):void
    # A new, unplaced widget of the same WBP, for per-player copies. false: no copies.
    NewCopy<public>():?entity

Widget is the entity whose fields are written: the placed widget, or a player's copy. The kit only calls a method when its value changes. InteractiveText(Value:string):message turns a string into a message for a WBP text field.

On this page