question

Never Rage Dungeons and Dragons avatar image
Never Rage Dungeons and Dragons asked

Get Character ID from the Server

Hi Guys,

I know how to grant a character with the cloudscript...how do I get the character Id...I tried using the client there was an error in the process. This will really help me..thank you!

CloudScriptCharacter DataCharacters
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

You can use Client API GetAllUsersCharacters or Server API GetAllUsersCharacters to get a specific player’s all characters’ CharacterId. Server API and Client API of GetAllUsersCharacters can both access all player’s CharacterId, CharacterName, CharacterType. Please refer to the following CloudScript code to get character Id from the server.

handlers.getUsersCharacters = function (args, context) {
   
    var request = {
        //You can modify the PlayFabId to any player’s one.
        PlayFabId: currentPlayerId, 
    };
  
    var getUsersCharacters = server.GetAllUsersCharacters(request);
    return {Characters:getUsersCharacters};
};<br>
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Never Rage Dungeons and Dragons avatar image Never Rage Dungeons and Dragons commented ·

There's what I want to do...I want to get the ID value in the server, and use that to

update, delete, or read the character.......I saw this, and its a perfect example of getting a data

but this one is a key, characterID is not a key. How do I get it still...I know the return method returns a the args...but can you explain this to me in a simplier term

//make an api call to the server for a string var

playerData = server.GetUserInternalData({ PlayFabId: currentPlayerId, Keys: ["last_move_timestamp"] });

//put the string into a variable var lastMoveTimestampSetting = playerData.Data["last_move_timestamp"];

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Never Rage Dungeons and Dragons commented ·

You can refer to the following code.

handlers.getUsersCharacters = function (args, context) {

    var request = {
        PlayFabId: currentPlayerId,
    };

    var getUsersCharacters = server.GetAllUsersCharacters(request);
    var characterId = getUsersCharacters.Characters[0].CharacterId;
    return { CharacterId: characterId };
};
1 Like 1 ·
Never Rage Dungeons and Dragons avatar image Never Rage Dungeons and Dragons Sarah Zhang commented ·

Thanks for helping me...I think I will just ignore this part of playfab.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.