Room based multiplayer (Auto State Sharing)

RNet has a rooms system where you can create a room with a name, for example "public" or "moon". These are independent from each other and you can have many rooms in your RNet server.

All players in the same room can 'see' each other. Players in RNet each share some data. Say their x and y coordinates in this global variable. All you need to do is share the information you want other players to see. They do the same.

global.sharedProperties = {
	_x : oPlayer.x,
	_y : oPlayer.y
}

This global variable can be updated from the object you control. For example if you have an oPlayer, then you can add this code to the step event of oPlayer.

Other players are automatically created and destroyed as they enter and exit the RNet room, making things simple to manage and understand.

//oOtherPlayer Step Event
x = SP._x
y = SP._y

What we did above is take the other person's shared properties and set the x and y to what was shared by the other player. This way, it comes full circle.

  1. Everyone was sharing their x,y coordinates.

  2. We took the general oOtherPlayer object and edited the step event so that we can use that shared information.

https://www.youtube.com/watch?v=ggG769JidBU

Last updated