Engine

core.engine.get_nickname

Client

Retrieves the current player username

Syntax

local username = core.engine.get_nickname(
    os_username = false
)

Parameters

TypeNameDescription
boolos_usernameDetermines which name is returned:
• When true - returns the operating system username
• When false - returns the nickname chosen in the main menu, falling back to the operating system username if none is set

Returns

TypeNameDescription
stringusernameCurrent player username, "Unnamed" if the operating system username cannot be resolved

The nickname can be changed at any time from the main menu.

  • Surrounding whitespace is trimmed from the nickname.
  • An empty nickname falls back to the operating system username.
  • Listen to peer:nickname:change to react when the name changes.

Examples

Prints current username
core.engine.print("info", "Current username:", core.engine.get_nickname())
Prints operating system username
core.engine.print("info", "OS username:", core.engine.get_nickname(true))
Greet the player with their nickname
local name = core.engine.get_nickname()
local os_name = core.engine.get_nickname(true)

if name ~= os_name then
    core.engine.print("info", "Welcome back, " .. name .. " (" .. os_name .. ")")
else
    core.engine.print("info", "Welcome, " .. name)
end

On this page