Simplified networking for GameMaker: Studio using the Patchwire multiplayer server framework
Yacc Game Maker Language
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
patchwire-gm Update to 1.1.0 Jun 25, 2017
LICENSE Update Jun 25, 2017

Patchwire for GameMaker: Studio

GameMaker client scripts for the Patchwire multiplayer server framework

Version 1.1.0

Compatible with Patchwire 0.2.*.


Download the latest .zip release of Patchwire's scripts and add them into your GameMaker project.


Creating a network manager object

// obj_network_manager - Create

This will initialize the client networking and connect to the given Patchwire server. Upon connecting, the client will receive a connected command. Let's go over how commands are handled next.

// obj_network_manager - Create

net_cmd_add_handler("connected", handle_connected);
// obj_network_manager - Networking

In the create event, we specify a handler script (handle_connected) for the connected command. In the networking event, we tell the Patchwire client to handle incoming commands. In this case, when the connected command is received, its contents will be sent to the handle_connected script, which can do whatever you please. argument0 in the handler script will be the ID of a ds_map containing the data sent from the server.

Writing command handler scripts

Lets use the example of writing a handler for a chat command from the server. We have connected to the server and added a command handler for the chat command to use handle_chat to handle the command. Let's say the server sends us a chat command that looks like this:

    command: 'chat',
    user: 'twisterghost',
    message: 'Hello, world!'

Patchwire will route this command into the handler, providing the command JSON as a ds_map, so we can handle it like this:

// Script: handle_chat
var data = argument0;
var fromUser = data[? "user"];
var message = data[? "message"];

show_message(fromUser + ': ' + message);

You do not need to handle deleting the data map after your handler script runs. Patchwire cleans it up for you.

Sending commands to the server

Sending a command is just as important as handling one, but much easier! To send a command, use the following syntax:

// Initialize the command, returns a ds_map
var command = net_cmd_init("SOME_COMMAND_TYPE_HERE");

// Optionally add data to the command
command[? "someKey"] = "someValue";

// Send the command to the server

That is all you need to do in order to send a command to the server. You can add as much or as little data to the command as you like.

NOTE: If you don't provide the command value in net_cmd_init, Patchwire will just send whatever the most recently created command was.


For more documentation, see:

GM Core

Patchwire-GM is a part of the GM Core project.