• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Sending map updates over a 2 player networked server/client game

C

Carcophan

Guest
Hello everyone.


I am struggling finding a way to 'convert' my one player game into a two-player game. Essentially, I messed up and built it from the ground up thinking I could just 'add' a second player to the screen, etc, but that is no where near close to how it works. Sad face. Reboot.



So, I think that I understand the basic concepts of client/server scripts now. I have downloaded a few from the marketplace and spent hours reading and watching videos (thanks to people like friendly cosmonaut), I even have gloomy net among other things. Problem has been, how do I convert the round peg into a square hole, when it comes to the MAP and sharing that between clients. I was able to rebuild it from scratch and to get it to work, on my 127.0.0.1 network.



My most recent setup is an initialization room with two buttons. One launches the server object, room and scripts. After that is loaded, a second instance of GMS is ran, and the client object, room and scripts are run for that.

I can get both client rooms to load with the same map, but I don't know how to update the maps between them once they are drawn. I can add players, and independently update EACH of the maps but I cannot get player 1's map change - to update on client/player 2's screen.

Anyone point me in a good starting direction or experience this themselves?

Example of the Async Networking from the Client:
Code:
type_event = ds_map_find_value(async_load,"type");
switch(type_event)
{
    case network_type_data:
        buffer = ds_map_find_value(async_load,"buffer");
        buffer_seek(buffer,buffer_seek_start,0);
        client_ReceivedPacket(buffer);
        break;
}

I was essentially able to get 'everything' else to sync between the two using just this data structure. What else is needed to send a 22/22 grid of 64px tiles? Click at X/Y and delete or add a tile, like 'lights out'.


[Edit] If randomization occurs on the serverobject, it has to be conveyed through to each of the client object(s). I am having trouble finding even good information on this. Is peer-to-peer the way I should be going? Or can a server object run and then clients connect to it.

[EDIT ] After some additional testing , it looks like putting the seed in the server, then loading the client off of THAT server object instance, will produce the same map on both client objects. I don't think this is the best way however.
 
Last edited by a moderator:
C

Carcophan

Guest
Heavy updates/title change, general bump.

I think the two 'edit' lines sum up the latest points/concerns that I have.



This is what I would use to remove a tile from the map, and want this tile to be removed from my opponents map.
Code:
//scr_Remove(xx, yy)
// Initialise vars
var _sz = 24;
var _grid = gridName;
var _cellx = (argument0 div _sz);
var _celly = (argument1 div _sz);
var _x = _cellx * _sz;
var _y = _celly * _sz;
var _rw = (room_width div _sz);
var _rh = (room_height div _sz)

// Check if given position is within the room bounds
if _cellx < 0 || _cellx > _rw - 1 || _celly < 0 || _celly > _rh - 1
{......
triggered by a mouse click, using something like: scr_Remove(xx, yy);



So I think this is what I have to somehow translate into a packet/buffer/message between clients. Maybe?
 
Last edited by a moderator:
Top