Display large numbers with commas

Hi There. I have used verse to display variable text on the players HUD. I am just trying to figure out how I can make the numbers read with commas. Eg. 1000 would display as 1,000 and 1000000 would display as 1,000,000 and so on. I have attached the code below:

using { /Fortnite.com/Devices }
using { /Fortnite.com/UI }
using { /Verse.org/Simulation }
using { /Verse.org/Colors/NamedColors }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/UI }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Assets }
 
# A Verse-authored creative device that can be placed in a level
ResourceUIDevice := class(creative_device):
 
    S2M<localizes>(S:string):message="{S}"
 
    @editable PlayerSpawners : []player_spawner_device = array{}
    @editable RefreshRate : float = 0.1
    @editable ConditButton : conditional_button_device = conditional_button_device{}
    var ResourceTextBlockPerAgent : [agent]?text_block = map{}
 
    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        for(PS:PlayerSpawners):
            PS.SpawnedEvent.Subscribe(PlayerSpawned)
 
    PlayerSpawned(Agent:agent):void=
        Print("Player Spawned")
        if(MyTextBlock:=ResourceTextBlockPerAgent[Agent]?){}
        else:
            AssignUI(Agent)
 
    AssignUI(Agent:agent):void=
        Print("Assigning UI")
        MyCanvas:=MakeCanvas(Agent)
        if:
            PlayerUI:=GetPlayerUI[player[Agent]]
        then:
            PlayerUI.AddWidget(MyCanvas)
            spawn{RefreshUI(Agent)}
 
    RefreshUI(Agent:agent)<suspends>:void=
        Print("Starting to Refresh")
        if(TextBlock := ResourceTextBlockPerAgent[Agent]?):
            loop:
                Sleep(RefreshRate)
                MyResource := ConditButton.GetItemCount(Agent,0)
                TextBlock.SetText(S2M("{MyResource}"))
 
 
 
    MakeCanvas(Agent:agent):canvas=
        Print("Making Canvas")
        MyTextBlock:=text_block:
            DefaultTextColor:=White
 
        if(set ResourceTextBlockPerAgent[Agent] = option{MyTextBlock}){}

 
        MyCanvas:=canvas:
            Slots:=array:
                canvas_slot:
                    Widget:=MyTextBlock
                    Anchors:=anchors{Minimum:=vector2{X:=0.0,Y:=0.0},Maximum:=vector2{X:=1.0,Y:=1.0}}
                    Offsets:=margin{Left:=216.0,Top:=820.0,Right:=1481.0,Bottom:=211.0}
                
                

        return MyCanvas

There’s some code here: Functions to work with ridiculously big numbers. | Uefn Code Snippet

hope that helps!

I finally figured it out. In your code change the following:
S̶2̶M̶<l̶o̶c̶a̶l̶i̶z̶e̶s̶>(̶S̶:̶s̶t̶r̶i̶n̶g̶)̶:̶m̶e̶s̶s̶a̶g̶e̶=̶"{̶S̶}̶"
S2M(S:int):message=“${S}”

and

T̶e̶x̶t̶B̶l̶o̶c̶k̶.S̶e̶t̶T̶e̶x̶t̶(̶S̶2̶M̶(̶"{̶M̶y̶R̶e̶s̶o̶u̶r̶c̶e̶}̶")̶)̶
TextBlock.SetText(S2M(MyResource))

1 Like

yeah i figured it out a couple of weeks ago and just forgot to mention it here. I did it the exact way you did it so I have marked it as the answer. Thanks

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.