B
Ben Hubble
Guest
i
Last edited by a moderator:
Located left of the 'Drafts' button (Floppy Disk) you will see a newspaper looking symbol... Select this then select 'Code' in the drop down box...Hope this helps, also how do I use the script tag ?
iid=0; //create instance iid variable
if (global.if_server){
iid=global.iid;
global.iid++; //global.iid will increase after each instance create on server!
//buffer create
var buffer = buffer_create(2, buffer_grow,1);
buffer_seek(buffer, buffer_seek_start, 0);
buffer_write(buffer, buffer_u8, 20)// msg id, i use 20 for create instance at client side
buffer_write(buffer, buffer_string, string(object_get_name(object_index)));// use asset_get_index on client side
buffer_write(buffer, buffer_u32, iid)//id for server - client
buffer_write(buffer, buffer_f32, x);
buffer_write(buffer, buffer_f32, y);
network_send_packet(global.socket, buffer, buffer_tell(buffer));
alarm[0] = 1; //can use alarm to send packet repeatedly
}
case 20:
var obj_v1 = buffer_read(buff, buffer_string); //instance name in string
var obj_v2 = buffer_read(buff, buffer_u32); //this is the custom id
var obj_v3 = buffer_read(buff, buffer_f32); // x
var obj_v4 = buffer_read(buff, buffer_f32); // y
var obj = instance_create(obj_v3, obj_v4, asset_get_index(obj_v1));
obj.iid = obj_v2; // see that the initial iid is 0 in zombie instance but changed here
obj.x = obj_v3; //set x position
obj.y = obj_v4; //set y position
break
case 21:
var obj_v1 = buffer_read(buff, buffer_string); //instance name in string
var obj_v2 = buffer_read(buff, buffer_u32); //this is the custom id
var obj_v3 = buffer_read(buff, buffer_f32); // x
var obj_v4 = buffer_read(buff, buffer_f32); // y
with(asset_get_index(obj_v1)){
if iid == obj_v2{
x = obj_v3;
y = obj_v4;
}
}
break
Newsflash: async_load is never an array.This came up, even though in my entire game, the only arrays i've ever used in my game so far is the alarm and async_load, which is not even in my obj_spawn or scr_check_spawn... soooooooo confused right now!
Take care about that statement! Desync can cause mass divergence very easily. There is plenty of reason even if the AI is the same that divergence can occur: difference in hardware, packet latency and loss etc. Small divergence becomes big divergence over time. This is why it's important to periodically sync everything together when necessary.You shouldn't need to do much of anything honestly. Send a packet on create and send a packet to the other player when its hit or destroyed. If the AI is the same, there is zero reason is should d-sync and even if it does, who is going to miss one stray zombie going a few pixels over?
Yeah, but this only lies true if you use hardware related calls such as random() or choose(). If the AI is all algorithmic then it should always play out the same. and even in cases of latency, its very rare for massive desyncs, but a client could resolve for this very easy by dividing latency by frame count and deciding how many frames to repeat an action till its caught up on this algorithmic AI, the most basic client prediction. Its not that big of a deal until you start expecting erratic outputs such as choosing random states, targets, or player input. That said, you're right to a degree. There should always be some kind of syncing, but you shouldn't need it nearly as much here. But the more you start syncing, the more client prediction you have to ad,because syncing pulls the clients millsecs back, you have to find creative and effective ways to hide the latency.Take care about that statement! Desync can cause mass divergence very easily. There is plenty of reason even if the AI is the same that divergence can occur: difference in hardware, packet latency and loss etc. Small divergence becomes big divergence over time. This is why it's important to periodically sync everything together when necessary.
It's also true if you are using a non-deterministic engine like Game Maker. Floating point non-determinism can result in huge divergence. It is particularly important in this case since it sounds like there would be many zombies.Yeah, but this only lies true if you use hardware related calls such as random() or choose(). If the AI is all algorithmic then it should always play out the same
///scr_update_enemy_pos(enemyid,x,y)
enemyid = argument0;
enemyx = argument1;
enemyy = argument2;
var i;
for(i = 0; i <= global.enemies_count; i++)
{
enemy = instance_find(obj_enemy,i);
if(enemy != noone) {
enemyid_check = enemy.enemyid;
if(enemyid == enemyid_check) {
with(enemy) {
x = obj_network.enemyx;
y = obj_network.enemyy;
}
}
}
}