question

giorgiotino avatar image
giorgiotino asked

Set initial entity Object for new players with CloudScript and PlayStream events

I need to detect when a player runs the game for the very first time and set an Object with default initial data. The Object will be called "PlayerData" and will of course consist of a JSON string.

What I have tried to do is:

- Create a CloudScript (initializePlayerData) that is triggered by the com.playfab.player_added_title PlayStream event. This script should call entity.SetObjects to set the default JSON string to the "PlayerData" Object.

The problem is that context.currentEntity is NOT set when the script is triggered by the event, so I cannot simply use context.currentEntity to make the SetObjects call as I already do, successfully, when I call ExecuteEntityCloudScript from Unity.

entity.GetEntityToken({}).Entity returns the 'title' entity

{ Id : context.playStreamEvent.EntityId, Type : context.playStreamEvent.EntityType } has a type of 'player' that seems not to be ok for the SetObjects call (Type is not valid?)

How do I get the current player entity to accomplish this goal?

I can of course find a way to do this from the client, but I would prefer to be able to do it automatically from the server CloudScript.

Player Dataentities
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

·
Seth Du avatar image
Seth Du answered

Would you add an additional GetTitlePlayersFromMasterPlayerAccountIds API call before the initiation process begins?

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.

giorgiotino avatar image giorgiotino commented ·


not sure what you mean exactly. GetTitlePlayersFromMasterPlayerAccountIds seems to be an Admin call that I cannot access from the CloudScript code handler that gets called when the com.playfab.player_added_title is triggered. I need to be able to access the Entity API from that event handler, but as I said context.currentEntity is not set, probably because the script gets triggered by the Rule using an ExecuteCloudScript call, and not an ExecuteEventCloudScript call... or am I missing something here?

I guess my question is how do I access the Entity API calls from within the com.playfab.player_added_title handler (in the Rules actions I only see Execute Cloud Script but I don't see an Execute Entity Cloud Script)

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ giorgiotino commented ·

It is not an Admin call. GetTitlePlayersFromMasterPlayerAccountIds is an Entity call, which can be executed by an entity token. Please refer to my code:

 handlers.contextTest= function(args, context) {
    var request = {
        "MasterPlayerAccountIds": [currentPlayerId]
    };
    var result = entity.GetTitlePlayersFromMasterPlayerAccountIds(request);
    return result;
}

I have tested it via Rule and it should work.

1 Like 1 ·
giorgiotino avatar image giorgiotino Seth Du ♦ commented ·

Oh that works, it was simple but I could have tried for days before figuring this exact thing out! Thanks a lot!

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.