# Source URL: https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-switch-devices-in-fortnite-creative
# Local doc: epic-docs/documentation/en-us/fortnite-creative/using-switch-devices-in-fortnite-creative.md
# Section: Using Switch in Verse
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# A Verse-authored creative device that can be placed in a level
switch_device_verse_example := class(creative_device):
# Reference to the Switch Device in the level.
# In the Details panel for this Verse device,
# set this property to your Switch Device.
@editable
MySwitchDevice:switch_device = switch_device{}
# Localizable messages that you can use to set player-facing text
TurnOnInteractionText<localizes>:message = "Custom switch turned on text!"
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
# Example for subscribing to an event on the Creative device.
# Signaled when the switch state changes.
MySwitchDevice.StateChangesEvent.Subscribe(OnStateChanged)
# Sets the *Turn On Text* to be displayed to a user when the switch is currently off, and offers an interaction to switch it on. Clamped to 150 characters.
MySwitchDevice.SetTurnOnInteractionText(TurnOnInteractionText)
# This function runs when the player turns the switch on/off in-game because it's an event handler for StateChangesEvent.
OnStateChanged():void=
Print("Switch Device state changed.")
# Query whether this device has a single global on/off state, or has a personalized on/off state for each individual agent.
if (MySwitchDevice.IsStatePerAgent[]):
Print("Switch Device state is set to per agent.")
# This example iterates through all players in the experience to show how to do operations per player on the device.
for (Player : GetPlayspace().GetPlayers()):
Verse Library
verse
01 Using Switch In Verse
Customizes switch interaction text and monitors on/off state changes for players.
extracted-snippets/documentation/en-us/fortnite-creative/using-switch-devices-in-fortnite-creative/01-using-switch-in-verse.verse
Sign in free to read the full source 🌴
This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.