31Nf4ChZ4H73N
Member
I am working on a multiplayer game. Therefore, I want to keep track of the units each player has. Thats why I create dynamic keys for each map.
I want that my ds_map looks like this at the end
I start with a ds_map which holds the general information of each possible unit.
Lets say player 1 has one infantry unit and one cavalry unit. I send this information to the server and the server saves it in the following way:
(
however, the second unit ("unit_1") does not get added to the ds_map. What did I do wrong?
Furthermore, when I delete dsm_client it also gets deleted out of the dsm_players map. I used to know how to prevent this but I dont have time for it right now.
I want that my ds_map looks like this at the end
GML:
"player1":{
"unit1":{
"name": "Infantry",
"hitpoints": 1
},
"unit2":{
"name":"Infantry",
"hitpoints":1
},
},
"player2":{
"unit1":{
"name":"Tank",
"hitpoints":2
},
"unit23":{
"name":"Infantry",
"hitpoints":1
}
}
GML:
function getDataUnits(){
return json_decode(@'
{
"infantry" : {
"name" : "Infantry",
"hitpoints" : 1
},
"tank" : {
"name" : "Tank",
"hitpoints" : 2
}
}');
}
dsm_data = getDataUnits();
(
GML:
//server side
dsm_players = ds_map_create();
//from the networking stuff
case network.sendUnits:
var unit = "unit_";
var dsm_client = ds_map_create();
var index = buffer_read(buffer, buffer_u8); //0
var unitkey = unit+string(index); //"unit_0"
var unitType = buffer_read(buffer, buffer_string); // e.g. "infantry"
ds_map_add(dsm_client, unitkey, dsm_data[? unitType]);
ds_map_add(dsm_players, socket, dsm_client);
var unit = "unit_";
var dsm_client = ds_map_create();
var index = buffer_read(buffer, buffer_u8); //1
var unitkey = unit+string(index); //"unit_1"
var unitType = buffer_read(buffer, buffer_string); // e.g. "tank"
ds_map_add(dsm_client, unitkey, dsm_data[? unitType]);
ds_map_add(dsm_players, socket, dsm_client);
break;
Furthermore, when I delete dsm_client it also gets deleted out of the dsm_players map. I used to know how to prevent this but I dont have time for it right now.