question

Timurs Sugajevs avatar image
Timurs Sugajevs asked

How to call ListMembership from Cloud Script?

I'm implementing guild system for my game and trying to wrap all client request's to cloud script functions. How to work with entities using cloud script? In some questions I saw "var entityProfile = context.currentEntity;", but it throws errors. Can someone provide example code for a wrapper to ListMembership function, so that I can figure out with the rest?

CloudScriptLeaderboards and Statisticsentities
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

Cloud Script is able to execute entity related APIs as there are samples in default revision. You may noticed the usuage like entity.SetObjects is called there.

Those enity related APIs can be executed by the client via API ExecuteEntityCloudScript.

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.

Timurs Sugajevs avatar image Timurs Sugajevs commented ·

Those examples does not work from client via ExecuteEntityCloudScript since context is not defined.


This is my cloud script code:

handlers.GetMyGuild = function (args, context)
{
  var entityProfile = context.currentEntity;
  return entity.ListMembership(entityProfile.Entity);
}
And this is my client (Unity) code: 
PlayFabCloudScriptAPI.ExecuteEntityCloudScript(new ExecuteEntityCloudScriptRequest(){FunctionName = "GetMyGuild"},(res) =>{Debug.Log(res);}, res => {Debug.Log(res);});

It returns errors related to undefined context.

So It should be another way to do it.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Timurs Sugajevs commented ·

This will work:

handlers.GetMyGuild = function (args, context)
{
  var entityProfile = context.currentEntity;
  var request = {Entity : entityProfile.Entity};
  var result = entity.ListMembership(request);
  return result;
}
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.