Multiplayer tutorial 2: chat room

25

Index

Features on these Courses

Stats

42,587 visits, 162,878 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 14 Mar, 2014. Last updated 29 Apr, 2024

Login layout

The first layout Login does not need much explanation. It is essentially just a text box with a Join button. The entered name is stored in a global variable and no connection actually happens until the next layout.

The events for the layout deal with focusing the text box, ensuring you can't join before typing in a name, and storing the entered name in the MyUsername global variable when joining.

Chat layout

The Chat layout connects in On start of layout, using the name stored in the MyUsername global variable.

The objects in the layout are designed to mimic a common chat room app: the main ChatLog is where chat messages appear, the PeerList on the right lists the names of the other people in the chat room, and there is a text box with a Send button along the bottom to send messages with. (You can also press return to send a message.)

The events for this layout will deal with:

  • connecting to the signalling server and logging in
  • joining the chat room
  • listing who else is in the room and updating the list as people join and leave
  • displaying received chat messages
  • sending any chat messages entered locally
  • dealing with any errors or disconnections that occur

We'll begin looking at the actual events on the next page of the tutorial.

  • 14 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Hi.i love construct.but I have a problem .

    only when peers and host,s adsl are same, it works can you help me.

    oh. and sorry.Im not english and its hard to write it.but I cant do any thing else.

    sorry. and please answer my question.

    thanks for your awesome program:construct.

  • Aren't chatrooms not allowed?

      • [-] [+]
      • 1
      • Ashley's avatar
      • Ashley
      • Construct Team Founder
      • 1 points
      • (1 child)

      You can make whatever content you like with Construct. However due to moderation problems, chat rooms are not allowed in the Construct Arcade. You can however publish chat rooms anywhere else.

  • How did you get the tab order to work on this? I see that I can tab from NameTextBox (UID 2) to RoomNameTextBox (UID 13) to JoinButton (UID 3). I can't find this anywhere and all my google searches say it can't be done, that you can only tab in order of UID, yet you did it in this project. Please help!!!

  • Hi, I tried to export the chat template to Android Debug apk and installed on my phone and try to host a room. It successfully connected and created the room as host. But when I try to connect another peer using my laptop browser it says connected as peer but will be kicked eventually. Am I missing something? Can I use multiplayer on Android device? Is the multiplayer plugin for browsers only?

  • sorry, where i can find the link to download the archive?

    • "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."

  • Load more comments (4 replies)