question

David Coombes avatar image
David Coombes asked

How to create characters (still confused about PlayFab's structure)

Working through the Entity tutorial, it seems easy to add data to the player. But when it comes to characters, I can't figure out how to get the Character Entity details, and then I realise I can't figure out how to even create a character. Heck, I don't even understand quite what it represents where we have suggestions that devs use Inventory to represent characters. Characters seem like they have to be created in Manager and granted? But then I can't find how to even define them in the Manager.

Let's say I have a party based RPG where the player can create their own characters. Or, a racing game where players can create their own cars made from parts. I want a record of each character/vehicle and its unique name and make-up, where the player can Create New Character that logs this new creation on PlayFab and attaches custom data via the Entity model. How do I do this?

game managerCharacters
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

Characters are objects within the player record which can have their own distinct statistics, inventory, currency, data, Entity objects and Entity file. Currently, we can use Server API Grant Character To User and Client API Grant Character To User to grant character to a player. Server API Grant Character To User can be used by CloudScript to grant characters to users directly. To use Client API Grant Character To User, you need to specify the Item ID of the item instance which is to be used to create the Character. So if you have an item in your Catalog with an Item ID of "FighterCoin", for instance, the client could call GrantCharacterToUser specifying that Item ID for the Character. The CharacterType in the resulting Character would then be "FighterCoin", so that you know what item was used to create it. The item that used to create a character should check its [Is a token for character creation] option.

After you grant characters to the user, you will get the corresponding character Id. Then you can use Entity API Set Objects and Get Objects to set and get its Entity Object. You can check the doc Entities quickstart for a sample ofhow to work with entity objects and entity files. In your case, please use this character Id as the entity Id, use “character” as the “Entity Type” and “Entity Type String”.

2 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.

David Coombes avatar image David Coombes commented ·

Thanks, but still haven't got it. ;)

You say an item from the Catalog is used to create the character. Does this item represent a template for a character, or is this just a reference for a sub-database 'character' created?

That is, if I have an item 'MagicBoots' in my catalog, and I used GrantCharacterToUser("MainCatalog", "NewCharacter", "MagicBoots"), does that create a character with the properties of the 'MagicBoots' item, or does it create a new child database called 'NewCharacter' that simply has 'MagicBoots' assigned as its character type?

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang David Coombes commented ·

>> You say an item from the Catalog is used to create the character. Does this item represent a template for a character, or is this just a reference for a sub-database 'character' created?

It’s more like a reference, but it’s actually a token for clients to grant a character to themselves. If clients don’t have a corresponding item, they don’t have access to grant characters to themselves. Server API does not have this limitation. ItemId will be character’s type.

>> That is, if I have an item 'MagicBoots' in my catalog, and I used GrantCharacterToUser("MainCatalog", "NewCharacter", "MagicBoots"), does that create a character with the properties of the 'MagicBoots' item, or does it create a new child database called 'NewCharacter' that simply has 'MagicBoots' assigned as its character type?

It will create a new child database called 'NewCharacter' that simply has 'MagicBoots' assigned as its character type.

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.