question

Alaa Adel avatar image
Alaa Adel asked

Auto-create an internal data key when a player is created

Hello,

I tried to use com.playfab.player_created rule to call a CloudScript function that creates an internal variable automatically for any player created. But it didn't work.

Here is the code:

handlers.Hello = function(args, context){
    server.UpdateUserInternalData({
        X_SecretKey: SECRET_KEY,
        PlayFabId, currentPlayerId,
        Data: {"kname": "0"}
    });
}


I figured it could be because of

currentPlayerId

Is not defined? And if so, how can I send it as an argument in the rule?
Replacing the Execute CloudScript with Grant Item works. So the event fires, but the function does nothing.

I am trying to avoid making the player initiate this event manually (i.e. calling ExecuteCloudScript from client)

Thank you.

CloudScript
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

·
Ivan Cai avatar image
Ivan Cai answered

After I check your cloudscript function code, I figure out the error:

X_SecretKey: SECRET_KEY,
PlayFabId, currentPlayerId,

change to:

PlayFabId: currentPlayerId,

In the server.UpdateUserInternalData API, "X_SecretKey: SECRET_KEY" is not used as a param.

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.

Alaa Adel avatar image Alaa Adel commented ·

Thank you!
I fixed the 2nd line in a comment after I posted, but it didn't show up for some reason!
After I removed "X_SecretKey: SECRET_KEY", it worked.

0 Likes 0 ·
Alaa Adel avatar image Alaa Adel commented ·

By the way, the docs say "X_SecretKey" is required in the header. Or is this meant that it is required if called by client, not by server? Because I found it strange that server would need a secret key in all the APIs!

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.