I have this code. An array of buttons and when a button is pressed I want to display in a hud_message_device which button was pressed.
# A Verse-authored creative device that can be placed in a level
UI_Announcer := class(creative_device):
@editable
HudMessageDevice : hud_message_device = hud_message_device{}
@editable
Waypoints : []button_device = array{}
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
for( Waypoint: Waypoints):
Waypoint.InteractedWithEvent.Subscribe(OnButtonInteractedWith)
OnButtonInteractedWith(Player:agent):void=
Print("button pressed")
HudMessageDevice.SetText(SetMessage("Button XXX pressed"))
HudMessageDevice.Show()
SetMessage<localizes>(MyMessage:string) : message = { "{MyMessage}" }
Can we add customer parameters on suscribe or at least in function OnButtonInteractedWith know which button was pressed beside knowing which player ?
There are a couple ways to do this in Verse. Here is one way using the concurrency system.
# A Verse-authored creative device that can be placed in a level
UI_Announcer := class(creative_device):
@editable
HudMessageDevice:hud_message_device = hud_message_device{}
@editable
Waypoints:[]button_device = array{}
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void =
for (I->Waypoint: Waypoints):
OnButtonInteractedWith(Waypoint, I)
OnButtonInteractedWith(Button:button, ButtonIndex:int)<suspends>:void =
# Suspends this function until Button.InteractedWithEvent is signaled
Agent:agent = Button.InteractedWithEvent.Await()
# ALTERNATIVE: If you don't care about the Agent:agent that triggered the button you can just await the event
# Button.InteractedWithEvent.Await()
# The inputs to the function are still around, so we can reference them after the InteractedWith event occurs
Print("Button {ButtonIndex} pressed")
HudMessageDevice.SetText(SetMessage("Button {ButtonIndex} pressed"))
HudMessageDevice.Show()
SetMessage<localizes>(MyMessage:string) : message = { "{MyMessage}" }
Is there a way of getting the name of the device in the editor. Because in this way I will get the index number as they where put in the array in the editor.
Is there a way of getting the name of the device in the editor. Because in this way I will get the index number as they where put in the array in the editor.
There is currently no way to get the editor display name for a device in Verse code.