How to send a function to all clients? (Networking)

To make my networking project, I followed along with a tutorial. I still don't understand networking fully, so I am not completely sure how to go about sending a variable that stores the creation of the bullet object.

GML:
create = instance_create_depth(obj_client.x, obj_client.y, 2, obj_bullet);

buffer_seek(con_client.client_buffer,buffer_seek_start,0);
buffer_write(con_client.client_buffer,buffer_u8,network.shoot);
buffer_write(con_client.client_buffer,buffer_?,create);
network_send_packet(con_client.client,con_client.client_buffer,buffer_tell(con_client.client_buffer));
What would I put where the question mark is?
 

chamaeleon

Member
You can't send game resources like that. You need to encode what you send as data that has meaning to the receiver. Just because you send the number 100048 (making up a random instance id), does not tell the receiver anything at all. You need to tell it to create an instance (if network.shoot is an enum, maybe that is sufficient), perhaps include coordinates saying where, perhaps something indicating which sprite (without using the sprite asset id), and so on. It all depends on what is required for a client to make decisions. It will perform its own instance creation function call, and anything that is needed to do this that only the sender would know is something you need to send explicitly.
 
Ideally you should be assigning your own ID to instances, because you have no control over the id game maker assigns (which is what you're trying to send there, stored in "create").

Instead, send specific attributes about the bullet to recreate it on the other end, such as its direction and who shot it. But again, to send who shot it, you'll need to have an ID system of your own.

As @FrostyCat says, netcode is like correspondence chess, you should give their explanation a read
 
Top