If someone could take a look at my code and give me some advice on how to improve it, I'd be very grateful.
Warning: This is fairly long.
Step event for the Host's character
if(global.master == true){
for(i = 2; i <= MaxPlayers; i += 1){
clearbuffer(0);
writebyte(myID, 0);
writeshort(x, 0);
writeshort(y, 0);
writeshort(image_angle, 0);
sendmessage(i, "", 0, 0);
}
}Begin Step Event for all other player's characters
if(global.master == false){
clearbuffer(0);
writebyte(myID, 0);
writeshort(x, 0);
writeshort(y, 0);
writeshort(image_angle, 0);
sendmessage(1, "", 0, 0);
}Step Event for the Host's Ghosts
if(global.master == true){
var size;
while(true)
{
size = receivemessage(myID, 0, 0);
if(size < 0) break;
if(size == 0)
{
show_message("The other player left the game");
game_end();
break;
}
messageid = readbyte(0);
if(messageid == myID){
x = readshort(0);
y = readshort(0);
image_angle = readshort(0);
break;
}
}
for(i = 2; i <= MaxPlayers; i += 1){
if(i != myID){
clearbuffer(0);
writebyte(myID, 0);
writeshort(x, 0);
writeshort(y, 0);
writeshort(image_angle, 0);
sendmessage(i, "", 0, 0);
}
}
}End Step Event for Player's Ghosts
if(global.master == false){
var size;
while(true)
{
size = receivemessage(1, 0, 0);
if(size < 0) break;
if(size == 0)
{
show_message("The other player left the game");
game_end();
break;
}
messageid = readbyte(0);
if(messageid == myID){
x = readshort(0);
y = readshort(0);
image_angle = readshort(0);
break;
}
}
}I'm also send the time every second.
The Host also spawns 1 minion every 30 seconds from 4 spawn points (So 4 minions total spawned at once) that sends it's x, y and image_angle to all the other players.
I start to encounter lag when:
-I increase the amount of players to 4 or above.
-I increase the amount of minions to 2 or above. (8 Minions total spawned at once - I can't increase it any less than this due to the system)
I realize I shouldn't send the X and Y every step, but I'm not sure how to do it any other way.
Thanks in advance for any help.











