Help about sync instances

Posted by DonovanNavarro
I'm trying to synchronize an arrow when the player shots, but many errors occur, such as the instance is not synchronized, and when it does the "image_angle" is always 180, look my code:

EVENT: PRESS SPACE FOR SHOT, OBJ_PLAYER

var i;

if (can_shot && !global.pause) {
i = instance_create(x,y,obj_arrow)
i.speed = 10
i.image_angle = obj_player.direction
i.image_speed = 0
i.direction = obj_player.direction
i.damage = obj_player.atk + baseATK

gms_instance_set_real(i,"damage",i.damage)
gms_instance_sync(i,is_onetime,"damage")
}

What's the problem? :(

Replies (1)

Last message on 18 May 2016

Size43 (Administrator) on 18 May 2016, 14:33:27
Note that gms_instance_set_real is not valid before calling gms_instance_sync.
GM8 / GM8.1:
The only variables that are synced by default are x, y, speed and direction. If you want to sync image_angle as well, you need to add it to the list. The code would then look like:
[gml]
gms_instance_sync(i,is_onetime,"damage","image_angle")
[/gml]

GM:Studio:
The only variables that are synced by default are x, y, speed and direction. If you want to sync image_angle as well, you need to call gms_instance_sync_var_add. The code would then look like:
[gml]
gms_instance_sync_var_add("damage", i.damage)
gms_instance_sync_var_add("image_angle", i.image_angle)
gms_instance_sync(i,is_onetime)
[/gml]
You'll also need to manually set the custom synchonized variables, because internally the extension uses variable_local_set, which is removed in GM:Studio. You'll need something like this in the user defined 12 event of obj_arrow:
[gml]
damage = ds_map_find_value(variable_map, "damage");
//Same for image_angle
[/gml]