Windows Problems with nested ds_ structures

BMatjasic

Member
Hello everyone! I am currently working on a networking engine, which I've been pretty successful, until the recent update I've made.
I am trying to store a map inside global.sessionList, which is stored and later found by any of the search scripts I've made. But when I've created another list and add another map in it, it just can't be found and I get an error that this data structure does not exist.

How do I do it:

How I create the list inside the map:

NOTE: global.sessionList is the pointer to the main list which is created at create event.


Code:
var playerList = ds_list_create();//Here we will create a list which will hold information about players INSIDE the session
var Session = ds_map_create(); //Let's create a session map and pass all the information we need to it
//Adding needed information to the session
ds_map_add(Session, "socket", Socket);  //add socket to session database NOTE: If you don't want to set master socket, just leave socket argument -1
ds_map_add(Session, "name", client_find_info(Socket, "name")); //add name of the room owner
ds_map_add(Session, "max_players", MaxPlayers); //add ammount of max players
ds_map_add_list(Session, "playerList", playerList); //Create list of players
ds_map_add(Session, "id", ds_list_size(global.sessionList)); //Add the id of this session
ds_list_add(global.sessionList, Session); //adding session to the current session list

How I add a map to that created list:

Code:
var Socket = argument0; //Pass socket argument
var SessionJoin = argument1; //Pass session argument

if(session_exists(SessionJoin) == true) {

    for(var i = 0; i < ds_list_size(global.sessionList); i ++) { //query for session data
  
        var sessionMap = ds_list_find_value(global.sessionList, i);
        var sessionId = ds_map_find_value(sessionMap, "id");
      
        if(sessionId == SessionJoin) { //Checks whether we found the correct session
          
            var playerList = ds_map_find_value(sessionMap, "playerList");
            var maxPlayers = ds_map_find_value(sessionMap, "max_players");
          
            //Now we need to encode a map with players who are in this session and send those info over
          
          
            if(ds_list_size(playerList) < maxPlayers) { //whether there is a free slot
                var playerName = client_find_info(Socket, "name");
              
                //Add values to a map
                var pMap = ds_map_create(); //Creates a dictionary for a player
                ds_map_add(pMap, "name", playerName);
                ds_map_add(pMap, "socket", Socket);
                ds_map_add(pMap, "x", -1);
                ds_map_add(pMap, "y", -1);
                ds_list_add(playerList, pMap);
                //ds_list_mark_as_map(playerList, ds_list_size(playerList) - 1);
              
                show_debug_message("List: "+string(ds_map_find_value(sessionMap, "playerList")));
                var def = ds_map_create();
                ds_map_add_list(def, "default", playerList);
              
              
                var json_playerList = json_encode(def);
                  
                ds_map_destroy(def);

And the script that gives me an error:

Code:
var SessionId = argument0; // Pass the socket argument

for(var i = 0; i < ds_list_size(global.sessionList); i ++) {

    var sessionMap = ds_list_find_value(global.sessionList, i);
  
  
    if(SessionId == ds_map_find_value(sessionMap, "id")) {
      
  
        return sessionMap;
  
    }
  
  

}
Thanks in advance, any help would be appreciated![/PHP]
 
Last edited:

Genetix

Member
I'm not entirely familiar with networking what is the exact error it gives? Doesn't appear to be a problem with your syntax if the compiler doesn't yell immediately - have to break it down step by step and identify exactly at which point it gets snagged. Could be an order of operations type of problem.
 

FrostyCat

Redemption Seeker
You forgot to use ds_list_mark_as_map() when adding the session to the list on the server side.

A breakpoint on the client-side receiving code would have easily revealed this problem.
 

BMatjasic

Member
@FrostyCat I do use it, but I didn't right now because of the debugging... I've remade a sample in which I also can't get to the exact point...

The output of this test is: 0

script add_player:


Code:
var name = argument0;
var idsearch = argument1;

for(var i=0; i < ds_list_size(global.list); i++) {

    var m = ds_list_find_value(global.list, i);
   
    if(ds_map_find_value(m, "id") == idsearch) {
     var l = ds_map_find_value(m, "list");
     var newlist = ds_list_create();
        for(var j=0; j < ds_list_size(l); j++) {
   
   var map = ds_map_create();
   
    ds_map_add(map, "name", name);
   
    ds_list_copy(newlist, l);
    ds_list_add(newlist, map);
ds_list_mark_as_map(newlist, ds_list_size(newlist)-1);
    ds_map_replace_list(map, "list", newlist);

}
}
}
Create event of object0

Code:
global.list = ds_list_create();

var map = ds_map_create();
var pList = ds_list_create();
ds_map_add(map, "name", "borut");
ds_map_add_list(map, "list", pList);
ds_map_add(map, "id", ds_list_size(global.list));


ds_list_add(global.list, map);
ds_list_mark_as_map(global.list, 0);



add_player("why", 0);
add_player("doesnt", 0);
add_player("it", 0);
add_player("work", 0);

and object1 key_press_enter
Code:
for(var i=0; i < ds_list_size(global.list); i++) {

    var pmap = ds_list_find_value(global.list, i);
   
    var playerList = ds_map_find_value(pmap, "list");
    show_message(ds_list_size(playerList));
    for(var j=0; j < ds_list_size(playerList); j ++) {
   
        var player = ds_list_find_value(playerList, i);
        var name = ds_map_find_value(player, "name");
        show_message(name);
   
    }

}
Maybe this will be easer to resolve?


Thanks in advance for ur time guys!

Download link to the file:

http://www.filedropper.com/dsstructuretest
 
Last edited:
Top