Engine
core.engine.get_nickname
ClientRetrieves the current player username
Syntax
local username = core.engine.get_nickname(
os_username = false
)Parameters
| Type | Name | Description |
|---|---|---|
bool | os_username | Determines 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
| Type | Name | Description |
|---|---|---|
string | username | Current 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:changeto react when the name changes.
Examples
core.engine.print("info", "Current username:", core.engine.get_nickname())core.engine.print("info", "OS username:", core.engine.get_nickname(true))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