Persistent Objects

So far we have seen 2 important concepts

  1. State Sharing in Rooms

  2. Sending a Single Message to a Client

Now let's talk about Persistent Objects. These are special objects that are stored on the server and do not 'belong' to any client like entities. They can be created room wise.

Anyone can Create, Edit, Delete these special objects because no one Client 'owns' it.

For example there is a ball on the server. Some client can join, move it around and leave. Then another client can join and move it starting from the same place the previous client left it.

oPersistentObject

This is the general object on gamemaker where you can customise the step event to do whatever you want. Here are the 2 most important properties.

persistentObjectId - Unique identifier of this persistent object. It is allocated by the server. Please do not edit this variable, only use it as a reference.

persistentObjectProperties - A stringified struct of the persistent object's properties. You can make sense of it like this. This code is preloaded so only the 2 lines in between are important.

// oPersistentObject Step Event
...
var pOp = json_parse(persistentObjectProperties)

/*
This is every instance of a persistent server object  in the room you are in
You can use the key-value pairs in these properties
to do stuff here. For starters, try updating
x = pOp._x
y = pOp._x
or whatever you want to update in any way 

Maybe someone left a ball in the room? This object can represent the ball.
The difference in a persistent object from normal entities is that
pO exist in the room even after the player exists the room or disconnects the server.
They are purely server side objects  which will stay unless you delete them
*/


	x = real(pOp._x)
	y = real(pOp._y)
	
...


Last updated