Skip to content

Commit

Permalink
Merge pull request #3 from twisterghost/version-2
Browse files Browse the repository at this point in the history
Version 2
  • Loading branch information
twisterghost authored Jan 26, 2017
2 parents 7df4a9d + efbf3c9 commit 9285d25
Show file tree
Hide file tree
Showing 50 changed files with 1,370 additions and 231 deletions.
40 changes: 24 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
# Patchwire for GameMaker: Studio
GameMaker client scripts for the Patchwire multiplayer server framework

Version 2.0.0

Compatible with [Patchwire 0.2.*](https://github.com/twisterghost/patchwire).

## Installation

1. Download the latest release of Patchwire-GM
2. In GameMaker, right click `Scripts` and select `Add Existing Script`
3. Select `patchwire.gml` from where you downloaded the release
Download the latest .zip [release](https://github.com/twisterghost/patchwire/releases) of Patchwire's scripts and add them into your GameMaker project.

## Use
## Usage

#### Creating a network manager object

```GML
// obj_network_manager - Create
net_init();
net_connect('YOUR_SERVER_IP', 'YOUR_SERVER_PORT');
net_connect("YOUR_SERVER_IP", YOUR_SERVER_PORT);
```
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.
```GML
// obj_network_manager - Create
net_cmd_add_handler('connected', handle_connected);
net_cmd_add_handler("connected", handle_connected);
```

```GML
Expand All @@ -44,35 +46,41 @@ Lets use the example of writing a handler for a `chat` command from the server.
}
```

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

```GML
// Script: handle_chat
var fromUser = net_cmd_read_data(argument0, 'user');
var message = net_cmd_read_data(argument0, 'message');
var data = argument0;
var fromUser = data[? "user"];
var message = data[? "message"];

show_message(fromUser + ': ' + message);
```
Here, `net_cmd_read_data` is used as a wrapper for `ds_map_read_value`. We pull out the data sent from the server and display it. Note that you do not need to handle deleting the map of data returned from the server, as it is automatically deleted after the handler is finished executing. You will, however, have to delete any lists or nested maps that may exist in the data, and if you need to store the data for more than just this execution, you will need to clone the data.
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:
```GML
// Initialize the command
net_cmd_init('SOME_COMMAND_NAME_HERE');
// Initialize the command, returns a ds_map
var command = net_cmd_init("SOME_COMMAND_TYPE_HERE");
// Optionally add data to the command
net_cmd_add_data('someKey', 'someValue');
command[? "someKey"] = "someValue";
// Send the command to the server
net_cmd_send();
net_cmd_send(command);
```

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.

## Contributing
> **NOTE:** If you don't provide the `command` value in `net_cmd_command`, Patchwire will just send whatever the most recently created command was.
# Docs

For more documentation, see:

If you would like to contribute to this repository, make you changes to the scripts in the `src` folder and create a pull request explaining your changes. A test suite will be coming soon using [Gamatas](https://github.com/twisterghost/gamatas) which will be run before merging pull requests. Until then, manual tests will be run on your branch.
* [Patchwire-GM Wiki](https://github.com/twisterghost/patchwire-gm/wiki)
* [Patchwire](https://github.com/twisterghost/patchwire)
28 changes: 28 additions & 0 deletions patchwire-gm/options/linux/options_linux.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions patchwire-gm/options/mac/options_mac.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions patchwire-gm/options/main/inherited/options_main.inherited.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions patchwire-gm/options/windows/options_windows.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9285d25

Please sign in to comment.