Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by Steven Gay · Jun 24, 2019 at 12:34 PM · apisunity3ddata

How to send List to cloud script? Not a Map,How to send a list of objects using ExcuteCloudScript? (not a dictionary)

Hi

I am trying to send a list of objects to the server - not a map but I couldn't find how to read it on the server.

public class Skill 
{    
   string name;
   int level;
   int skillpoints;
}

// LIST not MAP as the same skill can be trained several times
public static List<Skill> skillsInTraining = new List<Skill>();

public static void SaveSkillTrainingQueue()
{
        var test = PlayFab.Json.JsonWrapper.SerializeObject(skillsInTraining);


        var request = new ExecuteCloudScriptRequest
        {
            FunctionName = "SaveSkillTrainingQueue",
            FunctionParameter = new
            {
                skillsInTraining = skillsInTraining.Count,
                skills = test,
                
            },
            GeneratePlayStreamEvent = true
        };
        
        PlayFabClientAPI.ExecuteCloudScript(request, OnSaveSkillTrainingQueueSuccess, PlayFabBridge.PlayFabErrorCallback);
}

How can I access each skill.name and level in the server?

function SaveSkillTrainingQueue(args)
{
    var count = args.skillsInTraining;
    var skills = args.skills;
    
    log.debug("SaveSkillTrainingQueue count= " + args.skillsInTraining); // OK
    log.debug(" " + JSON.stringify(skills)); 

    //for (var skill in args.skills)
    //{
    //    log.debug(" " + JSON.stringify(skill));
    //    log.debug(" " + skill.name);
    //}

    var tmp = JSON.stringify(args.skills);
    for (var i=0; i<count; i++)
    {
        log.debug(i + "=" + tmp[i]);
        log.debug("name = " + tmp[i].name);  // <--------- NOK      
    }    
}

,

Hi

I am trying to send a List - not a Dictionary - of objects to be executed by a script.

public struct Skill { string name; int level; int skillpoint; }

// NOT a map as the same skill can be multiple times
public List<Skill> skillInTraining = new List<Skill>(); 

public static void SaveSkillTrainingQueue() {
        var test = PlayFab.Json.JsonWrapper.SerializeObject(skillsInTraining);

        var request = new ExecuteCloudScriptRequest
        {
            FunctionName = "SaveSkillTrainingQueue",
            FunctionParameter = new
            {
                skillsInTraining = skillsInTraining.Count,
                skills = test,
            },
            GeneratePlayStreamEvent = true
        };
        PlayFabClientAPI.ExecuteCloudScript(request, OnSaveSkillTrainingQueueSuccess, PlayFabBridge.PlayFabErrorCallback);
}

How can I access the values such as the skill.name on the server?

My attempts so far:

function SaveSkillTrainingQueue(args)
{
    var count = args.skillsInTraining;
    var skills = args.skills;
    
    log.debug("SaveSkillTrainingQueue count= " + args.skillsInTraining); // ok
    log.debug(" " + JSON.stringify(skills));  // nok

    //for (var skill in args.skills)
    //{
    //    log.debug(" " + JSON.stringify(skill));
    //    log.debug(" " + skill.name);   not found
    //}

    var tmp = JSON.stringify(args.skills);
    for (var i=0; i<count; i++)
    {
        log.debug(i + "=" + tmp[i]);
        log.debug("name = " + tmp[i].name);  // not found
        
    }   
}
Comment

People who like this

0 Show 1
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Steven Gay · Jun 23, 2019 at 07:45 AM 0
Share

humm... the text was send twice...

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by v_humcin · Jun 24, 2019 at 09:44 PM

Your method of passing in the list will work with a small change. The "skills" object is passed in as string, so you will need to use JSON.parse() instead of JSON.stringify() to turn it into a JSON object which will allow you to access the fields inside.

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    Related Questions

    Update part of a JSON 1 Answer

    Playfab randomly throws ServiceUnavailable / Timeout errors. 1 Answer

    Having trouble with getting invalid input parameters error when calling UpdateUserData. 1 Answer

    Question: Reading data from player account 1 Answer

    Trouble uploading a text file as an entity file onto playfab. 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges