using { /Fortnite.com/Devices } using { /UnrealEngine.com/Temporary/UI } using { /UnrealEngine.com/Temporary/Diagnostics } using { /Verse.org/Simulation } using { /Fortnite.com/UI } # This is our main device class. It inherits from creative_device # so it can live in the level and react to game events. toggle_message_board := class(creative_device): # Wire your Button device to this property in the # Verse Explorer (Details panel) after uploading. @editable ButtonDevice : button_device = button_device{} # We create an empty map to store widgets. # The key is the player. The value is the widget. var WidgetMap : [player]text_block = map{} # OnBegin runs automatically when the game session starts. OnBegin() : void = # Connect the button's InteractedWithEvent to our handler. ButtonDevice.InteractedWithEvent.Subscribe(OnButtonPressed) # This function runs every time the button is pressed. OnButtonPressed(Agent : agent) : void = # We need a player, not just an agent. Convert safely. if (Player := player[Agent]): # Get the player_ui interface so we can add/remove widgets. if (PlayerUI := GetPlayerUI[Player]): # Check if this player already has a widget in our map. if (ExistingWidget := WidgetMap[Player]): # The widget exists! Let's remove it. PlayerUI.RemoveWidget(ExistingWidget) # Remove it from our map too. set WidgetMap = map{} else: # No widget yet. Let's make one! NewWidget := text_block: DefaultText := StringToMessage("Hello, Player!") # Show the widget on this player's screen. # ZOrder 0 places it at the default layer. PlayerUI.AddWidget(NewWidget, player_ui_slot{ZOrder := 0}) # Save the widget in our map for this player. if (NewWidgetMap := WidgetMap.Clone[Player -> NewWidget]): set WidgetMap = NewWidgetMap