Getting started with UI

Labels

terrorsoul Beginner General Modding

Subtle messages disappear, but "labels" stay on the screen in a small UI window (Usually located in the top right of the screen). They're great for showing scores, instructions, or any text you want to keep visible.

To create a label we use this piece of code: 

tm.playerUI.AddUILabel(0, "mylabel", "label text")


In the above code, 0 would be the players id that you want to add the label for, mylabel would be the unique id for the label (This is useful if you need to edit/interact with the label later) and label text is the text that will be visible for the label.

If we take our previous OnModLoaded function, we can add our new label code to it. 

function OnModLoaded()
    tm.os.Log("My UI Mod is ready!")

    -- Send a quick message to *all* players.
    -- "Mod Started!" is the big text, "Welcome!" is the smaller text.
    -- The '3.0' means it stays for 3 seconds. The '' is for an optional image.
    tm.playerUI.AddSubtleMessageForAllPlayers("Mod Started!", "Welcome to the game!", 3.0, "")
tm.playerUI.AddUILabel(0, "mylabel", "Thanks for playing") end


If you now save the file and activate the mod you'll notice that a new window appears in the top right that says "Thanks for playing", this is the label and it will display for the player with the id of 0 (The host).


Previous Step
Step 4 / 4

Discussion

Please log in to post a comment.