I’m trying to change a button message in the canvas code but for whatever reason that doesn’t work. This is my code and I want to add an int to the button message:
# A canvas widget that displays a button with the text "Center" in the middle of the screen
CreateMyUI() : canvas =
MyCanvas : canvas = canvas:
Slots := array:
canvas_slot:
Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.5}, Maximum := vector2{X := 0.5, Y := 0.5}}
Offsets := margin{Top := 0.0, Left := 0.0, Right := 0.0, Bottom := 0.0}
Alignment := vector2{X := 0.5, Y := 0.5}
SizeToContent := true
Widget := button_loud{DefaultText := TextForUI}
return MyCanvas
Hi @NoahUEFN, to change the text in a button you need to create a localizedmessage instance (a string with localization information). You can then use the message when assigning to DefaultText or change the text later with the SetText function. eg:
# A localizable string message
TextForUI<localizes>:message := "Center"
# This function creates a localizable message with the given int value
MakeTextForUI<localizes>(Value:int):message = "Center {Value}"
# A canvas widget that displays a button with the text "Center" in the middle of the screen
CreateMyUI() : canvas =
MyButton : button_loud = button_loud{DefaultText := TextForUI}
MyCanvas : canvas = canvas:
Slots := array:
canvas_slot:
Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.5}, Maximum := vector2{X := 0.5, Y := 0.5}}
Offsets := margin{Top := 0.0, Left := 0.0, Right := 0.0, Bottom := 0.0}
Alignment := vector2{X := 0.5, Y := 0.5}
SizeToContent := true
Widget := MyButton
# Change the text message
MyButton.SetText(MakeTextForUI(42))
return MyCanvas