Skip to content

Player

AI Summary

A short gist of this page, generated for you.

Powered by AI. Summaries can miss nuance — when in doubt, read the page.

These calls tell your game who is playing. Players log in on Funox itself — your game only reads the result.

Accounts are optional for players, so every call here can report "nobody is logged in". Always handle that case.

#getUser()

Resolves with the logged-in player, or null for a guest. Call it after init() — the init() result never includes the player.

javascript
FunOxSDK.getUser().then(function (user) {
  if (user) {
    displayName(user.name);
    loadAvatar(user.avatar);
  } else {
    showGuestMode();
  }
});

#Player object

json
{
  "id": "user_id",
  "name": "PlayerName",
  "avatar": "https://cdn.funox.com/avatars/..."
}

In standalone mode getUser() always resolves with null.

#isLoggedIn()

A shortcut that resolves with true or false.

javascript
FunOxSDK.isLoggedIn().then(function (loggedIn) {
  saveButton.visible = loggedIn;
});

#getLanguage()

Resolves with the language the player is using on Funox, for example 'en', 'ar' or 'fr'.

javascript
FunOxSDK.getLanguage().then(function (lang) {
  setGameLanguage(lang);
});

#Reacting to login and logout

A player can log in or out while your game is open. Listen for the userChanged platform event:

javascript
FunOxSDK.on('userChanged', function (data) {
  if (data.user) {
    updatePlayerName(data.user.name);
  } else {
    showGuestMode();
  }
});

userChanged also fires once shortly after init() with the current player, so it is a reliable way to learn who is playing without calling getUser().

#Good practice

  • Never block gameplay behind a login. Guests must be able to play everything.
  • Use only the data the SDK gives you; do not ask players for personal information yourself.
  • See Account integration for the full rules.