YoYo Games Wiki

GM's Multiplayer Functions

From YoYoGames Wiki

Some or all of the functions in this article may work only in the registered version of Game Maker.

GM6 and GM7 both have multiplayer functions, so that you can play a game with somebody across the country, or... pretty much anywhere that you get internet.

Well sure, you can always just make a multiplayer game on one computer, where one player uses the arrow keys to move and annother uses the WASD keys to move. But what about more than two players? What if you wanted three players? Or four players. even five. six, seven, eight, nine, ten, eleven- well, you get what I mean. You can make a multiplayer game with so many players, it would be hard for a human brain to track. It only takes a lot of extra effort, and more than one computer to test it with.

Why do you even want to make a multiplayer game on one computer anymore? It's a lot more fun, and it would make your game so much better.

First off, these are the functions that you use to start multiplayer mode.

  • mplay_init_ipx() Initializes an ipx connection.
  • mplay_init_tcpip(address) Initializes an tcpip connection. This is the start function that I use because it is easy to use. The address can be either a website or an ip address. See below.
  • mplay_init_modem() and mplay_init_serial() I am not covering because the connection is slow and they are hard to use.

Both of these functions return weather they are successfull.

  • mplay_end() is the function you use to stop multiplayer mode.

when you call mplay_init_tcpip(), you need an address. You can enter an empty string, a website, or an ip address. if you enter a website, you need to make sure that it is in quotations, and that website will act like a game host. If you enter an empty string, then you are connected to computers close to yours. (local area computers.) if you decide to enter an IP address, then you need to enter the IP address of the computer you are connecting to. To get your computer's IP address for a friend, call this function:

  • mplay_ipaddress() returns your computer's ip address.

Annother function:

  • mplay_connect_status() returns the status of the current connection. 0 = no connection, 1 = IPX connection, 2 = tcpip connection.

Now that you know how to set up a connection, here's how to create and join sessions.

You can create and end sessions with these functions:

  • mplay_session_create(sesname,playnumb,playername) creates a new session on the current connection. sesname is a string indicating the name of the session. playnumb is a number that indicates the maximal number of players allowed in this game (use 0 for an as many as you can get). playname is your name as player. Returns whether successful.
  • mplay_session_end() ends the session for this player.

There are multiple functions that you can use to join an already made session. Here they are:

  • mplay_session_find() searches for all sessions that still accept players and returns the number of sessions found.
  • mplay_session_name(numb) returns the name of session number numb (0 is the first session). This routine can only be called after calling the previous routine.
  • mplay_session_join(numb,playername) makes you join session number numb (0 is the first session). playername is your name as a player. Returns whether successful.

so nobody can say I forgot about this function, I am mentioning mplay_session_mode(). I find it useless.

mplay_session_status() returns the status of the current session. 0 = no session, 1 = created session, 2 = joined session.

When you have joinded or have made a session, you can use the followind functions.

  • mplay_player_find() searches for all players in the current session and returns the number of players found.
  • mplay_player_name(numb) returns the name of player number numb (0 is the first player, which is always yourself). This routine can only be called after calling the previous routine.
  • mplay_player_id(numb) returns the unique id of player number numb (0 is the first player, which is always yourself). This routine can only be called after calling the first routine. This id is used in sending and receiving messages to and from individual players.

also only after you have created a session, you can use these to communicate between all of the players.

  • mplay_data_write(ind,val) write value val (string or real) into location ind (ind between 0 and 1000000).
  • mplay_data_read(ind) returns the value in location ind (ind between 0 and 1000000). Initially all values are 0.

messages, i have never used before, so I am not going to try to explain them.