Referencia de funciones
Godot 4 · GDScript · Players
set_newname
Changes the player's display name (server validates uniqueness + charset).
Asynchronous (result via signal)
Signature
set_newname(new_name: String) -> boolWhat it does
PATCHes /players/name. Sanitizes the name locally first, then lets the server validate uniqueness. newname_completed status: 1 = applied, -1 = name taken, 0 = generic failure. attempted_name echoes the sanitized request; applied_name is the name the server actually set.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| new_name | String | required | Desired name; sanitized locally and capped at 30 chars. Must be at least 2 chars after sanitizing or the call is rejected. |
How to call it
Connect newname_completed first, then call set_newname(). Returns false immediately if there is no active session or the sanitized name is shorter than 2 characters (no signal is emitted in that case).
Result signal: newname_completed(status: int, attempted_name: String, applied_name: String)
Example
Gamdato.newname_completed.connect(_on_rename)
if not Gamdato.set_newname("Hero123"):
print("rejected locally (no session or too short)")
func _on_rename(status: int, attempted: String, applied: String) -> void:
match status:
1: print("renamed to %s" % applied)
-1: print("that name is taken")
0: print("could not change name")Use cases
- Let the player pick a nickname during onboarding.
- Offer a rename option in a settings screen.