GameSalad & PlayFab: Part 2

Posted by

I am going to dive into it immediately. This being part 4 of a series of posts, if you are lost, please read the other 3 entries.

I want to mention that I don’t have any special documentation. What I have done so far is based on a lot of trial and errors and trying to figure out how the engine works by using “console.log(<object>)”, trying random commands to see if they return anything, and what is available in the Legends of Learning integration files. This is all to say that if you have a better way please share.

Here are the steps to get the “avatarId” back into the game and on changing the avatar in the game writing it back to PlayFab:

  1. Originally I was going to use the “TweetSheet” command inside GameSalad to send out the new avatar number. Unfortunately, I am unable to get any of the values that I put into that function out. Instead, I am using the “PostScore” command. Not ideal because I also want to post the score to the leaderboard, but it will have to do. Inside of my GameSalad game, I post a score of <new avatar number> with the leaderboard “changeAvatar.”
  2. Once that is done we go back to our integration file cordova-app.js and we first create a method to update any userData. It accepts two values the key and the updated value. I placed it near the top where I placed all the other new methods.
    • updateUserData: function(value, key) {

              function updateUserDataCallback (result, error) {

                  if (result !== null) {

                      console && console.log && console.log(result);

                      

                  } else if (error !== null) {

                      console && console.log && console.log(error);

                  }

              }

              var data = {};

              data[value] = key;

              var userDataRequest ={

                    Data:data,

                    Permission: “Public”

              };

              PlayFabClientSDK.UpdateUserData(userDataRequest, updateUserDataCallback);

          },

  3. I then hijack the postScore function and send the value returned from within GameSalad to the new method:
    • onGameCenterPostScore: function (score, leaderboard) {

                          if (leaderboard === “changeAvatar”) {

                              app.updateUserData(“avatar”,score);

                          }   

      },

  4. To make this all work I have to write the value that comes back from PlayFab (yesterday’s blog post) into the attribute inside the game. All of the examples in the Legends of Learning file had the attribute id as “game.attributes.id<attribute for avatar>” but when I looked inside object.js file (from the HTML export) none of my attributes are named that way. I don’t know if it is because I am using the desktop version of GameSalad, an old version, or Legends of Learning is using a special build. Searching for the avatar attribute I found the id. I can then use that id to update the avatar attribute inside the game. Like this:
    •           gse.Game.externalWriteGameAttribute(‘game.attributes.id187673’, result.data.Data.avatar.Value);     

  5.  And finally, I decided to make a video of all it working.

I want to mention that although I using Cordova, the PlayFab integration should work on a strickly web export also.

In the next coming days, I plan to flush out everything I can do with this integration. Getting the display name, sound option and anything else that I can think of and then I am going to try to figure out how to update a table without touching the table files (if I can).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.