How to convert message type to string type?

I am using a old function that adapts a string to a maximun number of char for a single line, so I add line breaks when the line is too long.

I need to convert the message to a string to use my old code or at least know how I can adapt my message to add line break

Hey @davidpkami how are you?

You can use a code similar to this one to localize (not convert directly) you message to a string if the message contains variables inside:


using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

message_to_string := class(creative_device):

    # Localizable message function that takes a player parameter and returns a formatted message
    MyMessage<localizes>(Player:player) : message = "Player: {Player}"
    
    # Editable button device that can be configured in the UEFN editor
    @editable
    MyButton : button_device = button_device{}

    # Override function that runs when the device starts in a running game
    OnBegin<override>()<suspends>:void=
        # Subscribe the OnButtonPressed function to the button's interaction event
        MyButton.InteractedWithEvent.Subscribe(OnButtonPressed)

    # Function called when the button is pressed by an agent
    OnButtonPressed(Agent : agent) : void =
        # Get all players currently in the playspace
        AllPlayers := GetPlayspace().GetPlayers()
        # Check if there is at least one player and assign it to FirstPlayer
        if (FirstPlayer := AllPlayers[0]):
            # Call MyMessage function with the first player to generate a localized message
            MessageWithPlayer := MyMessage(FirstPlayer)
            # Convert the message to a string using Localize()
            MyString : string = Localize(MessageWithPlayer)
            # Print the converted string to the UEFN log
            Print("Converted message to string: {MyString}")

Keep in mind that if you are using player names, for instance, you won’t get the real player name but something like this:

This happens becasue player names are not available as a string in UEFN.

If the message is only text, you can use this code instead:


using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

message_to_string := class(creative_device):

    # Localizable message function that takes a player parameter and returns a formatted message
    MyMessage<localizes> : message = "Hello World!"
    
    # Editable button device that can be configured in the UEFN editor
    @editable
    MyButton : button_device = button_device{}

    # Override function that runs when the device starts in a running game
    OnBegin<override>()<suspends>:void=
        # Subscribe the OnButtonPressed function to the button's interaction event
        MyButton.InteractedWithEvent.Subscribe(OnButtonPressed)

    # Function called when the button is pressed by an agent
    OnButtonPressed(Agent : agent) : void =
        MyString : string = Localize(MyMessage)
        Print("Converted message to string: {MyString}")

Hope this helps you!