Synchronising instances

Before you start

This tutorial assumes you already have a basic game that shows a login box and has a "player object" and an "other player object" set up. If you don't, the getting started tutorial covers the basics of creating a new game.

This post will consist of two parts. In the first part, I'll cover the ideas and theories behind instance synchronization. I'll explain what the different types of instance synchronization are, and when to use them. In the second part, I'll show how to get instance synchronization to work in your game.

In this tutorial, I'll use the word "client" a few times. A client is an instance of the game, connected to the server. For example, if there are three players playing your game, that means three clients are connected to the server. When a player moves, that moment is sent from one client to the other clients.

Different types of instance synchronization

There are three basic types of instance synchronization: One-time, Extended and Full synchronization. Every type of synchronization can be local or not local.

One-time instance synchronization synchronizes the instance exactly once. It does not synchronize it's destroy or any variable that changes after it's synchronized.

Extended instance synchronization will synchronize the instance twice: Once when calling gms_instance_sync(...), and once when the instance is destroyed. This type of synchronization does not synchronize any variables that are changed after creating it.

Full instance synchronization will synchronize the instance when calling gms_instance_sync(...), when a variable changes, and when it's destroyed. This type of synchronization is very similar to how the "player object" is synchronized. Instances will be sent to other players when they join the room.

Local instance synchronization will only synchronize the instance if it's close to the player. It'll try to predict which instances will be seen by the player, and the server will only synchronize those instances. For full instance synchronization, the instance will still be synchronized to other players, but its variables and position are only synchronized if the player is close enough to the instance.

Whether the player can see the instance or not, is determined by the "Syncing-distance". This distance can be set on the site, under Developer -> Game-settings -> Syncing distance. A good estimate for how large the Syncing distance should be, is to take the room_width or room_height (whichever one is higher) and multiply it by 1.5.

Each type can be represented by a constant:

  • One-time synchronization: is_onetime

  • Extended synchronization: is_extended

  • Full synchronization: is_full

By default, these constants are all not local. To make one of the synchronisation types local, its constant must be bitwise or'ed ('|') with the constant isc_local. (bitwise operators are outside the scope of this tutorial, there are some great tutorials about bitwise operators out there if you're interested) For example:

is_onetime | isc_local

is_extended | isc_local

is_full | isc_local

When to use what type

When creating a multiplayer game, it's important to keep the data usage to an absolute minimum. Instance synchronization can use a lot of data. Therefore, it's important you use the right type of synchronization for the right type of instance.

To decide what type of synchronization you need, you should consider whether the moment an instance is destroyed and how and when the instance moves or changes variables is predictable.

For example: A bullet is destroyed when it collides with a wall. Because a collision with the wall will happen at the same time on all clients, it is not necessary to synchronize the destroy of the bullet.

On the other hand, assume an object is destroyed when a player clicks on it. Not all players will click on the same object at the same time, so for the other clients there is no way of knowing, without explicitly sending the destroy to the other clients, whether the instance has been destroyed.

The same goes for movement or variables. If the value of the variable or the position of the object is predictable, it does not need to be sent.

The points above can be formulated in 3 questions:

  • "Is it possible to know what the value of a variable of the object is and will be without sending it?"

  • "Is it possible to know what the position of the object is and will be without sending it?"

  • "Is it possible to know at what moment in time the object will be destroyed, without sending it?"

Each different type of instance synchronization will fulfil a different need:

  • One-time synchronization: position predictable, destroy predictable, variables predictable.

  • Extended synchronization: position predictable, destroy unpredictable, variables predictable.

  • Full synchronization: position unpredictable, destroy unpredictable, variables unpredictable.

Note how not all possible combinations are covered. The three types are the most common ones. There aren't many cases where the value of variables is unpredictable, but the position is.

That's all you need to know to get started. Keep in mind you'll most likely (and should) use One-time and Extended synchronization most of the time. Full synchronization uses a lot of CPU power and data compared to the other two options, so use it with care!

Adding instance synchronization to a game

Now that I've covered the different types of synchronization and when to use them, I'll use this second part of the tutorial to show a few examples & describe how to add instance synchronization to your game. I'll be using the game created in the getting started tutorial as a start.

Make sure you've set the Syncing distance on the GameMaker Server website.

I'll cover two of the three different types of instance synchronization here:

  • One-time instance synchronization

  • Full instance synchronization

Extended instance synchronization is very similar to One-time synchronization.

Shooting (One-time synchronization)

Create a new object and name it "obj_bullet" and give it a sprite.

Open obj_player, and add a Global Mouse Left Pressed event.

GM8 / GM8.1:

Add the following piece of code:

i = instance_create(x, y,obj_bullet);
i.speed = 8;
i.direction = point_direction(x, y,mouse_x, mouse_y);
i.damage = random_range(30,50);
gms_instance_sync(i, is_onetime | isc_local, “damage”);

GM:Studio:

In GM:Studio, you'll need to do a little more work when synchronizing an instance variable. Note how in the GM8 code above, the custom variable is indicated to the extension by simply passing a string containing the variable name to gms_instance_sync(...). Internally the extension will use variable_local_get to obtain the variable value. In GM:Studio variable_local_get is removed.

GameMaker Server has a special function that is used to set both the variable name and value for instance synchronisation, gms_instance_sync_var_add(...). Add the following piece of code to the Global Mouse Left Pressed event:

i = instance_create(x, y,obj_bullet);
i.speed = 8;
i.direction = point_direction(x, y,mouse_x, mouse_y);
i.damage = random_range(3050);

gms_instance_sync_var_add(“damage”,i.damage);
gms_instance_sync(i, is_onetime | isc_local);

Regardless of what type of synchronization you're using, these variables are only sent once to the other clients. The variables x, y, speed and direction are always sent.

Once the instance is created on the other clients, the User Defined 12 Event is called.

GM:Studio:

You'll also need to manually set the custom synchonized variables, because internally the extension uses variable_local_set, which is once again, removed in GM:Studio. Open obj_bullet and add this piece of code to the Event User 12 event:

damage =ds_map_find_value(variable_map, “damage”);

variable_map is a variable is a variable that contains a ds_map with all the synchronized variables in it. The ds_map is destroyed after the User Defined 12 event has executed.

The speed and direction (and any custom variables / the variable_map variable) are not set in the create event of obj_bullet. You must use the User Defined 12 event if you want to use the synchronized variables.

The game is now in a state you can run it. If you want, you can test what you have so far.

If you want, you can add walls to your game. Try adding a piece of code that'll destroy the bullet once it hits a wall. (remember, when obj_bullet hits a wall is predictable).

Try giving the player health and make the bullets do damage to the other players. Keep in mind obj_other_player is only a representation of the obj_player object on another client. Handle the collision with obj_bullet in obj_player only. To check if the player fired the bullet, use special owner variable that's automatically set after calling gms_instance_sync(...).

Spawning & synchronizing enemies (Full synchronization)

Let get on to something more advanced. Create an object and name it obj_npc. For the purpose of this tutorial, give it a completely white sprite. We'll use that later on to assign a random image_blend color to every NPC.

In the create event:

  • Set alarm[0] to 1 second

  • Set the speed to 4

Add this code to the alarm[0] event:

direction= choose(090180270);
image_blend =irandom(c_white);
alarm[0] = room_speed;

GM:Studio:

Add a call to randomize() in the GMS object or another initialization object to make sure the NPC will walk randomly every time.

Destroy the instance when it hits a bullet.

Create an object named obj_npc_spawner. Make it spawn obj_npc every 3 seconds, until there are 5 obj_npcs walking around:

Create:

alarm[0] = room_speed * 3;

Alarm[0]:

alarm[0] = room_speed *3;
if(instance_number(obj_npc) < 5)
{
 instance_create(x, y, obj_npc);
}

When tasked with changing the code above to synchronize the instance every time it's created, your first reaction would probably be to just add a gms_instance_sync below the instance_create line. Though that would work, it also creates a problem. Consider this: If 3 players are online at the same time, every single client will have the obj_npc_spawner spawn an NPC every 3 seconds. That means 3 NPCs will spawn every 3 seconds. If 5 players are online, every 3 seconds up to 5 new NPCs will spawn.

To keep the spawn rate the same, only one client should create instances. To decide which client should spawn the instances, the master player can be used. The master player is assigned by the server to one client, and will change automatically when a player logs out or other players join. Change the code to this:

alarm[0] = room_speed *3;
if(gms_self_ismaster())
{
 if(instance_number(obj_npc)< 5)
 {
 instance_create(x, y, obj_npc);
 }
}

GM:Studio:

Because image_blend is a built-in variable, it can be obtained and set by the extension automatically. There's no need to add a call to gms_instance_sync_var_add(...) in this case.

Note the alarm will go off regardless of whether the player is the master player or not. This is done so that in case the master player disconnects, the alarm on the client that becomes the next master player is still running. The gms_self_ismaster() check is done every 3 seconds on every client to make sure another client will be able to pick up seamlessly when the master player disconnects.

The NPC object itself will also need to be changed a little. If every client tried to change the direction of the NPC every second, it would get a mess very quickly. The obj_npc object would move in multiple directions at the same time, because every client set it to a different direction. That's why an instance can only be controlled by one client at a time. The instance is "owned" by a particular instance. The functions gms_instance_is_owner(id) and gms_instance_get_owner(id) will return whether the client owns the instance and what player owns the instance respectively.

Unlike the master player, instances do not change owner automatically. Every instance will need to be handed over to another player by calling gms_instance_handover(...) or gms_instance_handover_all(). The server will decide what player the instance is handed over to. This means if you don't want instances to be destroyed when a player moves to another room or logs out, you need to hand over instances in these events:

  • Room end

  • Game end

Edit the alarm[0] event of obj_npc:

if(gms_instance_is_owner(id))
{
 image_blend = irandom(c_white);
 gms_instance_set(id,“image_blend”, image_blend);
 direction = choose(0,90180270)
}
alarm[0] = room_speed;

Add this code to the step event to update the image_blend variable if the instance is not owned by the client:

if(!gms_instance_is_owner(id))
{
 image_blend = gms_instance_get(id, "image_blend");
}

Lastly, make sure the instance is handed over to another player when the owner of the instance disconnects or changes room:

Game End & Room End event:

if(gms_instance_is_owner(id))
{
 gms_instance_handover(id);
}

You may want to add an Outside Room event to obj_npc, and make it warp in both directions to keep the NPC's on the screen. Add an instance of obj_npc_spawner to rm_play.

That's it!

Finally. This tutorial is much longer than I intended to make it, but I wasn't able to make it any shorter without removing parts of the tutorial. Let me know what you think! If something is unclear, please ask about it in the comment section below, or send me a PM on the GameMaker Forums. What subject should I do next?

Replies (94)

Last message on 25 Sep 2017

Vitiik on 10 Sep 2016, 14:05:26
How to make matchmaking? I need help. I am making WW2 Platform shooter mp game and I need matchmaking.
Size43 (Administrator) on 16 Sep 2016, 09:24:19
You can use the VS mode for this. Please see the total shotgun / vs mode example in the download for an example.

You can also manually implement this using the [acticle=sessions]sessions[/article].
Vitiik on 26 Jul 2016, 14:10:40
Hello I have problem with

x = obj_player.x
y = obj_player.y
Vitiik on 1 Aug 2016, 12:50:05
When I run it. the Object with x = obj_... magnet to player and player has got two objects on same place.

Sorry for bad english
Size43 (Administrator) on 1 Aug 2016, 20:02:51
Check if the "owner" variable of the object equals gms_self_playerid(), and only update the position if that's the case.
Size43 (Administrator) on 26 Jul 2016, 17:39:40
Hey,

Please explain the problem in a little more detail. Are you seeing an error? What are you expecting to happen, and what is actually happening?
Mert69 on 3 Sep 2017, 19:43:58
Hey!
Great tutorial! Yet, I still have some problems with the one time bullet sync. The bullets get synced and all, but on the other client the direction is opposite and they dont have an image_angle, please help me, thanks!

code:
var i=instance_create(lengthdir_x(x+5,point_direction(x,y,x,y)),y,oBullet)

with i
{
i.speed=26
i.direction=other.image_angle + random_range(-3,3)
i.image_angle=direction
i.damage=1

gms_instance_sync_var_add("damage",i.damage)
gms_instance_sync(i,is_onetime | isc_local) }
}
Size43 (Administrator) on 4 Sep 2017, 11:47:05
You'll need to sync the image angle manually, just like the damage.

I believe the speed can only handle a value between -10 and 10. You might need to set a smaller value.
Mert69 on 4 Sep 2017, 14:52:12
Thanks! It helped me a lot! Yet, I still have one problem; the player uses a seperate "oGun" instance to create the bullets, the gun is created in the create event of the player but when the second player joins, the gun of the second player follows the host. How do I solve that?
Size43 (Administrator) on 4 Sep 2017, 14:54:25
You can make each player be followed by just one gun like this:

// Create
my_gun = instance_create(x, y, oGun)
// Stop
with my_gun
{
    x = other.x
    y = other.y
}
Mert69 on 4 Sep 2017, 15:00:09
Thanks for the fast reply! I did this, but it isnt really what I want, I want the gun to follow the player and be visible on all the clients. Right now it is visible for both clients, but on the host's screen the other gun sticks to the host too, and on the other client's screen the host can shoot 2 bullets at the same time but he doesnt have 2 guns. Sorry if its unclear, I dont really know how to explain this.
Mert69 on 4 Sep 2017, 15:03:32
Isn't there any way to check what instance created the gun? So I can tell the gun to follow the player who created it.
Size43 (Administrator) on 4 Sep 2017, 16:05:06
You can get the owner (player id that created the instance) of a synced instance using gms_instance_get_owner(id).
Mert69 on 4 Sep 2017, 16:32:54
Hmmm when I use that, it just ignores the code.

///End step
var owner=gms_instance_get_owner(id)

if instance_exists(owner)
{
x=owner.x
y=owner.y+3.5
}
Size43 (Administrator) on 25 Sep 2017, 16:09:15
Apologies for the delay.

gms_instance_get_owner returns a player_id. You can't use that with instance_exists.

In this case, you can just use gms_instance_is_owner().
Mert69 on 4 Sep 2017, 16:33:26
So the gun doesn't stick to the player now, it just floats.
Mert69 on 6 Sep 2017, 16:37:24
Can someone please help?
romzelized on 5 Feb 2017, 17:01:35
hey, my game isnt syncing the objects, ive done this a couple of times, but it didnt work, can you help me?
Size43 (Administrator) on 16 Feb 2017, 15:57:44
Can you post the code you're using?
mpgame on 1 Dec 2016, 17:07:50
hey...
when I set the type of instance synchronization to "is_full", the intensive shaking is seen in movement of synched object. So that, my object moves very bad for other player... (I use the gravity, vspeed and changing x for movement). can you tell me a solution for this problem?
Size43 (Administrator) on 2 Dec 2016, 13:49:32
You can try using a different prediction method. See gms_optimize_set_spc
mpgame on 8 Nov 2016, 19:35:42
Hey again!
What is mean of "You must use the User Defined 12 event if you want to use the synchronized variables."???
For example how we can draw value of "damage" variable after adding this piece of code to the Event User 12 event:
damage =ds_map_find_value(variable_map, “damage”);
mpgame on 9 Nov 2016, 17:13:22
At the moment, I draw the "damage" value as usual, but it don't show new synced value for other player!
Size43 (Administrator) on 10 Nov 2016, 12:16:22
You can just draw the variable damage after adding the code in the User Def. 12 event.

Can you add a show_message(damage) in the User Def. 12 event to see if the value is being read correctly?
mpgame on 10 Nov 2016, 19:12:01
I added "show_message(damage)" in the User Def. 12... but show_message opened just in first time! After changing damage value, it didn't open and therefore, the value of damage don't synced in next times.

My Game Maker Studio version is 1.4.1598.
Size43 (Administrator) on 11 Nov 2016, 12:09:42
By default, variables are only synced on instance creation. If you want them to be continually synced, you'll need to use gms_instance_get and gms_instance_set.
conanphamtuan on 26 Oct 2016, 18:24:51
i think you should add flag that the sync instances in another client are the same variables with variables of the first instances
Size43 (Administrator) on 28 Oct 2016, 17:24:37
I'm sorry, I don't quite understand.
matthe815 on 1 Dec 2016, 21:50:01
Let me try to translate it to English. "I think you should add a flag that syncs another clients variables with the instance owner."
Size43 (Administrator) on 2 Dec 2016, 13:55:48
You could just use the variable syncing for this. See gms_other_get and gms_self_set.
gmfk07 on 14 Jul 2016, 20:27:46
Hey! First of all, I've just heard of GMserver and I'm looking forward to using it in future projects.

I've just been looking through the documentation, and after reading this tutorial, I have a quick question - is every instance given a client as its owner automatically by the server?
Size43 (Administrator) on 25 Jul 2016, 17:15:47
Apologies for the delay. I've been working a lot in the past few weeks, at some points up to 10 hours a day. That left very little time for me to do anything besides work.

Every instance is automatically owned by the client that created it, and will not change ownership until gms_instance_handover(_all) is called, or the player disconnects / changes session.
Bukmang on 19 Mar 2016, 19:17:10
Help me the instance doesn't get created in other client!

iD=instance_create(x, y, obAttacks);
iD.image_xscale=image_xscale;
iD.sprite_index=sprite_index;
iD.aType=aType;
iD.ddDamage=8.6;
iD.mask_index=sprite_index;

if aType=0 iD.ddDamage=8;
if aType=1 iD.ddDamage=7;
if aType=4 iD.ddDamage=10;
if aType=5 iD.ddDamage=12;
if aType=6 iD.ddDamage=9;

iD.image_speed=image_speed;
iD.hspeed=hspeed;
iD.Stick=Stick;
iD.image_index=0;

if Stick!=0 && skType[2]=1 {
iD.visible=1;
iD.sprite_index=spStickmanAttack_05;
iD.Stick=0;
}

if Stick!=0 && skType[1]=1 {
iD.visible=1;
iD.sprite_index=spStickmanAttack_04;
iD.Stick=0;
}

if serConnected=1 {
gms_instance_sync_var_add("aType", iD.aType);
gms_instance_sync_var_add("ddDamage", iD.ddDamage);
gms_instance_sync(iD, is_full);
}
Size43 (Administrator) on 26 Mar 2016, 20:54:24
Are both players in the same room?

Are both players logged in?

Is serConnected = 1 true?
Bukmang on 28 Mar 2016, 12:27:28
Yes, Yes and Yes, and I fixed, the sprite was empty so when I assisned iD.sprite_index=sprite_index it was empty so I had to do this gms_instance_sync_var_add("sprite_index", sprite_index); and it worked, and sometime the game lags or slow, why is that?
Size43 (Administrator) on 1 Apr 2016, 14:11:45
Depending on the distance you're away from the server (Amsterdam, The Netherlands) you might experience some lag. There's a discussion about that here:
http://gamemakerserver.com/en/forum/board/3/view/89/
amkgames on 15 Dec 2015, 19:43:41
I am having lronlem synchronizing allies, In my game allies follow player and I want allies to be synced to other clients and it does but ally starts following other player...
May you help me to solve this problem?
Thanks! :)
(I have one more problem but I will say that someday later.) lol
Size43 (Administrator) on 22 Dec 2015, 15:44:51
You might find gms_instance_is_owner useful :)

It sounds like the allies all start following the player object. You'll only want them to start following if the instance is owned by the current player (= if that function I linked returns true).
amkgames on 27 Dec 2015, 15:24:58
Also, how do I destroy other player's ally when other player logout?
Size43 (Administrator) on 28 Dec 2015, 22:11:41
Add a small script to check if a player_id is logged in:

//player_id_exists
for(var n = 0; n < gms_other_count(); n += 1)
{
    if gms_other_find(n) == argument0
        return true;
}
return false;


Now you can check if the player still exists, and if not destroy the follower using:

if !player_id_exists(gms_instance_get_owner(id))
{
    instance_destroy()
}
amkgames on 29 Dec 2015, 18:18:51
Where to put that code? It is not working in step event, I even tried putting it inside if gms_instance_is_owner and is not owner.
(It destroys when I put it outside of gms...owner when it creates and it does same in gms...owner but it never destroys in is not owner...)
Size43 (Administrator) on 30 Dec 2015, 15:49:43
The first code should be in a script named player_id_exists, the second part should be inside the if !gms_instance_is_owner(id) { ... } inside the ally-object.
amkgames on 1 Jan 2016, 11:11:02
That's what I have done but other player's ally never destroys and it starts following player.
I will try to fix it myself, it should work I add some variable s and make sure that it is other player's ally.
Size43 (Administrator) on 1 Jan 2016, 13:13:54
Wait, do you want the instance to be destroyed when the player logs out (which is what the code I gave you should do) or when the player goes to another room as well?
amkgames on 1 Jan 2016, 13:28:12
Both.
Btw, Happy New Year! :)
Size43 (Administrator) on 5 Jan 2016, 12:11:03
The code I gave will only work for when the player logs out -- you might have to just hide the ally when the player is in another room (the other player object will be at a position like (-10000,-10000) when the player is in another room).
amkgames on 6 Jan 2016, 07:36:20
What if I make a parent object of other player and set it parent of other player and othe ally(new object)?
Size43 (Administrator) on 11 Jan 2016, 12:31:46
I don't think this will work.
amkgames on 5 Jan 2016, 12:55:51
Something like this?:
if obj_other_player.x = -10000 and obj_other_player.y = -10000
{
//hide code
}
Size43 (Administrator) on 11 Jan 2016, 12:31:36
Just checked, you can just check if visible is set to true. Should be easier :)
amkgames on 11 Jan 2016, 13:53:04
You mean I have to use the above code and hide code should be: visible = true or false?
Size43 (Administrator) on 17 Jan 2016, 21:20:17
You can replace the check for x and y with an if other_player.visible = true.
amkgames on 18 Jan 2016, 06:02:32
Thanks, but do other players get only unvisible if went to another room?
Do they still sync to previous room?
Size43 (Administrator) on 18 Jan 2016, 17:19:50
Unless you're manually setting them to be invisible, they will only be invisible when they're in a different room.
amkgames on 11 Feb 2016, 10:16:06
Also, this error is being hateful >_<:
___________________________________________
ERROR in
action number 1
of Begin Step Event
for object __newobject79:
Retrieving owner for non-existing instance 108671.000000
amkgames on 11 Feb 2016, 10:18:15
Do my instance not exists?
Size43 (Administrator) on 16 Feb 2016, 17:54:12
It seems like you've got some instances that aren't synced properly. Maybe you're missing a gms_instance_sync somewhere?
amkgames on 16 Feb 2016, 19:15:19
I am using gms_instance_sync in create event of object_player before instance_create of obj_ally and that sync is is_full.
When I switch ally, following ally object is changed to fighting ally object and when I change fighting ally to following ally, this error occurs.
Does that mean I need to sync it again? (Of course I think. :P)
Size43 (Administrator) on 16 Feb 2016, 20:55:02
Yeah that might be the problem. Let me know if syncing it again fixes it.
amkgames on 11 Feb 2016, 09:57:20
Invisible thing is working but logout thing is still not working. :/
Size43 (Administrator) on 16 Feb 2016, 17:54:39
What's the logout thing?
amkgames on 16 Feb 2016, 19:17:37
Btw, long time no see. :P
Size43 (Administrator) on 16 Feb 2016, 20:51:23
Yeah, I've been sick for a few weeks.
amkgames on 17 Feb 2016, 05:39:37
Oh, if you are still sick, I hope you get well soon. :)
Size43 (Administrator) on 21 Feb 2016, 21:23:53
Thanks! Don't worry, it's nothing serious. :)
amkgames on 16 Feb 2016, 19:08:05
The code you gave to destroy ally when player logout.
Size43 (Administrator) on 16 Feb 2016, 20:53:15
Try setting the script and destroying the instance manually using gms_script_set_logout.
amkgames on 17 Feb 2016, 05:44:08
I will try it, looks cool! :)
Thanks!
amkgames on 18 Jan 2016, 17:27:12
Oh, Thanks! :D (I had spell mistake. :P invisible*)
amkgames on 26 Dec 2015, 13:26:45
I can't understand how to use it... Is it used something like this?:
var owner_id;
owner_id = gms_instance_get_owner(oPlayer.id);
if gms_instance_is_owner(owner_id)
{
follow(owner_id); //Example.
}
amkgames on 27 Dec 2015, 14:32:49
But I want to sync sprite index of that ally...
I've tried gms_instance_set and get... but it didn't worked.
I am using it something like this:
//Step Event of Ally object
if !gms_instance_is_owner(id)
{
sprite_index = gms_instance_get(id,"sprite_index");
}
//Then sprite changing code with movement code
//and then this:
if gms_instance_is_owner(id)
{
gms_instance_set(id,"sprite_index",sprite_index);
}
amkgames on 27 Dec 2015, 14:46:29
This the error I get when other client connects:
___________________________________________
ERROR in
action number 1
of Draw Event
for object follow_ally:
Trying to draw non-existing sprite.
Size43 (Administrator) on 28 Dec 2015, 22:08:43
gms_instance_get might return 0 if the variable is still being sent over, and not received by the other player. Add a if(sprite_exists(...)) before setting sprite_index, and it should work.
amkgames on 29 Dec 2015, 18:19:23
Thanks! :)
amkgames on 27 Dec 2015, 14:27:13
I have changed the code and it is working. :P
if gms_instance_is_owner(id)
{
follow(obj_player);
}
amkgames on 26 Dec 2015, 13:27:40
Ally's Step Event. ^
amkgames on 26 Dec 2015, 11:19:12
Sorry for the late reply, I found this mail in spam...
amkgames on 26 Dec 2015, 11:07:01
Sounds interesting, Thanks! :)
(I forgot the second problem xD, I will say when I will remember.)
amkgames on 15 Dec 2015, 19:44:02
Problem*
Aaron13ps on 28 Nov 2015, 06:05:30
Dear Size,

Is there a way to make an instance sync only locally? I am trying to find a way to create an attack that is synced only if the player is connected to a session (to prevent lag in the lobby). But I would still like the player to be able to fire his/her weapon in the main lobby but only client side in order to prevent lag. Is there any way around this without creating an entirely different object strictly for client side? (Some of the data is loaded in user_event_12)
Size43 (Administrator) on 7 Dec 2015, 11:43:17
It might be easiest to just call user event 12 manually if you don't want to sync it. I don't think gms_instance_get will return an error when the instance does not exist, but I'm not 100% sure about that so that may require some more checks.
WWW_cool on 6 Sep 2015, 11:21:07
Dear Size,

Are all build-in vars of GMS auto sync? (for example - alarms)

- Artem
Size43 (Administrator) on 6 Sep 2015, 20:57:12
Alarms are not synced. An alarm does not have a direct effect on the object, so I decided not to sync them automatically. If it changes the sprite, the sprite will be synced. If it changes position, the position will be synced and so on. You get the idea.
captain_davy on 1 Jul 2015, 14:50:05
Dear Size,

I am a big fan of this tutorial and all your great work, but I am having a little trouble with it. I have chosen to make my own master/owner system using an avarage of gms_info_ping() to determine the player with the lowest latency and assigning him the role as master, to ensure that the player with the best connection is always the one syncing the instances in a local area. This has been working great so far in choosing the initial owner of a synced instance, instead of the randomly assigned gms_master_player. However, when my system finds a new master with a better connection, handing over the instance to that player has proven to be a bid of a challenge. It seems as if the only way to do this is through the custom gms_instance_handover(id) or gms_instance_handover_all(), which leaves me no choice as to who the instance should be handed over to. I hope that there is a way around this, and that you could find the time to help me out.

- Davy
Size43 (Administrator) on 2 Jul 2015, 19:47:43
There's no way to specify which player will get the instance after it's handed over. I like the idea of giving the instance to the player with the lowest ping, so I'll add it to the logic for switching instance owners. I'm not planning on adding a manual selection right now, but it may be added in the future.
SlamminSam on 4 Jun 2015, 02:22:01
Great tutorial :)
Size43 (Administrator) on 5 Jun 2015, 16:31:51
Thanks!
simi on 1 Apr 2015, 13:31:31
i try full synchroized but i get this error any help ? thanks...
___________________________________________
############################################################################################
ERROR in
Retrieving owner for non-existing instance 100005.000000
at gml_Script_XSe
action number 1
of Step Event0
for object GMS:
rver_error (line 3) - show_error(argument0, false);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_XServer_error (line 3)
called from - gml_Script_gms_step (line 167) - XServer_error(gms_action_get_argument_string(0));
called from - gml_Object_GMS_StepNormalEvent_1 (line 1) - gms_step();
simi on 1 Apr 2015, 15:23:23
this error show up when the obj_npc is create on the obj_npc_spawner
Size43 (Administrator) on 3 Apr 2015, 11:46:38
Would you be able to mail me your project (or something that generates the same error) to gamemakerserver@outlook.com so I can take a look at it?
Miksamoo on 3 Oct 2014, 13:43:48
I have tried to do bullet. When it collides with player, it checks owner. But that gets error:

############################################################################################
ERROR in
action number 1
of Step Event0
for object GMS:

Retrieving owner for non-existing instance 100004.000000
at gml_Script_XServer_error (line 3) - show_error(argument0, false);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_XServer_error (line 3)
called from - gml_Script_gms_step (line 159) - XServer_error(gms_action_get_argument_string(0));
called from - gml_Object_GMS_StepNormalEvent_1 (line 1) - gms_step()

I use this code on collision event with player:
if !gms_instance_is_owner(id) {
other.hp -= dmg
instance_destroy()
}
Size43 (Administrator) on 3 Oct 2014, 18:44:03
Apologies about that. That function actually only works for instances that are synced using is_full (as they can change owner). For the is_onetime and is_extended, a variable named owner is set for every instance. This variable will contain the player_id of the owner of the instance. This code does the same as the gms_instance_is_owner for fully synced instances:

if owner == gms_self_playerid()
{
    ...
}
Orbacal on 17 Aug 2014, 22:04:06
Hello. I have to use full type sync in my game to make some compex mechanics work (like charging, deflecting bullets), But that seem to occassionally freeze and crash the game for me and others. Is it possible to prevent these extreme lags?
Size43 (Administrator) on 19 Aug 2014, 20:20:51
That should not happen. If there's any way to reliably reproduce this, please let me know how. Other than that, if the game crashes (...not responding) please send me a dump file (task manager -> Right click on process -> Create dump file).