Multiplayer tutorial 2: chat room

Favourite 88 favourites
Tutorial written by AshleyOriginally published on 14th, March 2014 - 3 revisions

This tutorial assumes you have already read Multiplayer tutorial 1: concepts.

The easiest introduction to the multiplayer object in Construct 2 is a simple chat room. This only has to deal with connecting and joining the room, other peers joining and leaving, and relaying simple chat messages. Some of the more complicated topics like input prediction and lag compensation are simply not necessary since there is no object the player controls. These will be covered in the next tutorial, but for now we can focus on the basics and still produce something useful.

To get going, open the Example: Multiplayer - chat room example that comes with Construct 2. This can be found in the Select template or example dialog that opens when pressing File - New. While this example is already commented, this tutorial will explain it event-by-event in more detail, since some of the features take a little more explaining than is convenient in event comments.

Running and testing

To preview the example, you must run it from the first layout (F4). If you run the Chat layout directly, it will not be able to join the chat room, since it needs a valid name entered from the Login layout.

When testing the tutorial multiplayer games, it's possible you will meet other people who happen to be running the tutorial at the same time. However users commonly go "away from keyboard" (AFK) and leave things running without attending to them, so don't be surprised if other people are present but don't respond to chat messages. If you don't happen to meet someone active, get a friend involved and do some testing with them!

It's also possible someone will already be hosting the tutorial but you won't be able to connect to them. If that happens, change either the game, instance or room name and you'll start a new game which you host yourself.

Share and Copy this Tutorial

You are free to copy, distribute, transmit and adapt this work with correct attribution. Click for more info.


Tedg 9,893 rep

Wow this is fantastic .!

Friday, March 14, 2014 at 3:36:23 PM
GodSpear 2,766 rep

Спасибо хороший

Friday, March 14, 2014 at 4:00:21 PM
RamPackWobble 31.0k rep

Thanks for this - its going to need a few reads before it gets through my thick skull, but I'm sure it will.

Friday, March 14, 2014 at 4:40:00 PM
iceangel 33.5k rep

chat room ... interesting!!!

Friday, March 14, 2014 at 4:53:08 PM
jardelbr 4,893 rep

PERFECT! Chat room is so much important for MP games!

Friday, March 14, 2014 at 6:06:41 PM
AllanR 18.5k rep

VERY Exciting stuff!!! Can't wait to get started!

Friday, March 14, 2014 at 7:04:49 PM
exertia 2,630 rep

@Ashley - say my game can only work well with 2 players i.e. one host and one peer - is there anyway I can limit my multiplayer sessions to 2 players only?

Friday, March 14, 2014 at 8:40:35 PM
sggs 3,575 rep

Thanks for laying the foundation for all my new games.

Friday, March 14, 2014 at 9:40:55 PM
edisone 18.3k rep

very very interesting...

Saturday, March 15, 2014 at 4:01:29 PM
Mohorelien 3,220 rep

We'll translate these tutorials soon.

Sunday, March 16, 2014 at 12:59:32 PM
Matiu 921 rep

So awesome:D One question however I am trying to get the chat example to work on a server with https protocol. I get this message...

Connecting to server...
Signalling error: SyntaxError: Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. 'https' is not allowed.

Anyone know if it is possible to run multiplayer over a https connection?

Monday, March 17, 2014 at 9:24:17 AM
Ashley 202.3k rep

@Matiu - the signalling server uses secure websockets, not https. The connection is already secure (since it uses wss: instead of ws:).

Monday, March 17, 2014 at 4:53:33 PM
Matiu 921 rep

Thanks Ashley, I have since been reading up on wss:)

Tuesday, March 18, 2014 at 7:49:36 AM
Miu3 8,106 rep

Can you maybe later describe more the signaling server part? Can we use this address for our own projects forever? Any possible tutorials for other alternatives?

Wednesday, March 19, 2014 at 10:00:58 PM
fassFlash 4,377 rep

Civilization V uses a system where when the host leaves the game, another player with the best connection/at random gets the host position. Can you implement this in the example?

Sunday, March 23, 2014 at 10:01:42 AM

Leave a comment

Everyone is welcome to leave their thoughts! Register a new account or login.