GMCloud and GameMaker Part 4: Player Profiles

Yuan Gao (Meseta)
2 min readJan 9, 2019

--

Now that we’ve successfully linked a player’s account to the game in Part 3, the game is now able to access user data. The first thing that a game is likely to want to access is the player profile, which includes key information about the player which may be useful to display, such as the displayName.

A special property of fetching a user’s profile is that this increments a “login count” which can be used to track how many times a player has “logged in”. This mechanism is purely a statistic available for the game to use, and has no functional properties otherwise. For example, a game developer may decide to reward players for signing in a certain number of times.

This tutorial assumes you’ve completed and understood in Part 1, Part 2 and Part 3, as it relies on previous setups and understanding.

Step 1: Grab the saved linkId and Secret if you don’t have it already

We need the player’s linkId and Secret in order to access their profile. In Part 3, we previously stored the linkId and Secret in a ds_map_secure_save. So we should restore it:

var data = ds_map_secure_load("link.data");
if (data != -1) {
// ...
}

Ideally you would do this at the start of the game, or on a profile selection screen, and then keep the linkId and Secret in a variable for use later, rather than re-read the file every time.

Step 2: Make the request for the player profile

uuid = gmcloud_get_profile(data[? "linkId"], data[? "linkSecret"]);

As previously described in Part 2, this function sends out the request for the profile, but only returns a request ID, which is used to later check for the result (which may arrive several frames later).

As always, make sure this code does not repeatedly run. See Part 2 for implementation details for this.

Step 3: Check for and fetch the result

if (gmcloud_result_exists(uuid)) {
var result = gmcloud_result_pop(uuid);
// ... do something with result
}

By now you will be used to this way of doing things. This will remain the case for other functions too

Step 4: Parse the result

The result from the server is JSON encoded, and will have several keys of data relating to the player’s profile, for example “displayName” will contain the user’s currently set display name.

if (gmcloud_result_exists(uuid)) {
var result = gmcloud_result_pop(uuid);

var data = json_decode(result);
global.name = data[? "displayName"]

ds_map_destroy(data)
}

Here, we save the displayName to a global variable.

That’s it! As you can see, once you’ve got API tokens set up, and functionality to link a user account, interacting with GMCloud servers is relatively straightforward. Take a look at the demos in the marketplace asset for more examples.

Next in Part 5, we’ll finally cover cloud saves!

--

--

Yuan Gao (Meseta)
Yuan Gao (Meseta)

Written by Yuan Gao (Meseta)

🤖 Build robots, code in python. Former Electrical Engineer 👨‍💻 Programmer, Chief Technology Officer 🏆 Forbes 30 Under 30 in Enterprise Technology

No responses yet