GMCloud and GameMaker Part 2: Game Configs

  • Message of the Day (MotD): A small message to display to the player. This might be as simple as showing a message to remind players to upgrade their game when a new release comes out.
  • Timed unlocks and special events: Perhaps at a certain time, a new area or new feature of the game unlocks. You don’t want players to be able to just fast-forward their system clock and fool the game into thinking it’s the future already.
  • Game balancing: Maybe you want to be able to re-balance the stats in your game or tune certain game parameters. Normally you’d need to send out a new update to do this, but pulling game balancing values from a server instead would allow you to update the game balance across every copy of your game without making your players update.

Step 1: Write a message

JSON-formatted game config
  • plaint text: maybe you don’t need anything fancy, just a single string to show
  • ini: you could write an ini data just like an ini file, and have GameMakerini_open_from_string()
  • buffer: you could store a base64-encoded buffer, and have GameMakerbuffer_base64_decode()
  • ds_grid or other datastructures: GameMaker’sds_grid_read()and other _read() functions of other datastructures use string-based serialization. You could generate the grid data in a GM program, write out the serialized version with ds_grid_write() and copy the result into the config.
  • any other string-serialized data: as long as it’s a string, and you have the appropriate deserializers, any data is possible

Step 2: Issue the request for the Game Config

uuid = gmcloud_get_config();
Asynchronous polling for the result

Step 3: Check for a result

if (gmcloud_result_exists(uuid)) {
...
}

Step 4: Fetch the result

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

Step 5: Parse the result

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

show_message(data[? "motd"]);
global.some_stat = data[? "some_stat"];
}

Tips for implementing the asynchronous result poll

Method 1: Use the create event

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

Method 2: Use an undefined value

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

Method 2b: Add a timeout and retry

uuid = undefined;
timeout_counter = 0;
if (is_undefined(uuid)) {
uuid = gmcloud_get_config();
timeout_counter = 0;
}
else {
timeout_counter ++;
if (timeout_counter > 600) {
gmcloud_result_cancel(uuid);
uuid = undefined;
}

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

Method 2c: Add error checking

uuid = undefined;
timeout_counter = 0;
if (is_undefined(uuid)) {
uuid = gmcloud_get_config();
timeout_counter = 0;
}
else {
timeout_counter ++;
if (timeout_counter > 600) {
gmcloud_result_cancel(uuid);
uuid = undefined;
}

if (gmcloud_result_exists(uuid)) {
var result = gmcloud_result_pop(uuid);
// ... do something with result
}
else if (gmcloud_error_exists(uuid)) {
var error = gmcloud_error_pop(uuid);
// ... do something with error
uuid = undefined;
}
}

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The HTTP Status Codes Problem

100 Days of Code Challenge

update page mockup

Being an effective PM at home

How to Speed Up VMWare, Oracle VirtualBox and Microsoft Hyper-V Virtual Machines

Test-With-Expect: A BDD-style Go naming pattern

How Much Does It Cost To Create An App Like Groupon

How to quickly set up OpenPBS on Ubuntu 20.04 for single node workload scheduling.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yuan Gao (Meseta)

Yuan Gao (Meseta)

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

More from Medium

Is it a bug? Change via defects

How to Make a Interactive Camera using Cinemachine and C#

Immersion Starts with Sound!

twinBASIC Update: January 23, 2022