list does not exist

Pfap

Member
I am creating a list in a script and filling it with data, which I later access from an object. I don't get the error when accessing from the script, but later in the object it crashes.

Compile output:
ds_list_find_value(global.opponent_card_list,0)
13

ERROR!!! :: ############################################################################################
ERROR in
action number 1
of Create Event
for object opponent_cards:

Data structure with index does not exist.
at gml_Object_opponent_cards_Create_0 (line 7) - var start_one = ds_list_find_value(global.opponent_card_list,0);
############################################################################################
Here is the script which has the debug messages shown on the first 2 lines in the quote above:

Code:
global.opponent_card_list = ds_list_create(); 
//grab the initial 3 cards 
ds_list_add(global.opponent_card_list,ds_list_find_value(card_net_list,0));
ds_list_add(global.opponent_card_list,ds_list_find_value(card_net_list,1));
ds_list_add(global.opponent_card_list,ds_list_find_value(card_net_list,2));
ds_list_destroy(card_net_list);
show_debug_message("ds_list_find_value(global.opponent_card_list,0)");
show_debug_message(ds_list_find_value(global.opponent_card_list,0));
And this is the object code:

Code:
//it crashes here, but not in the script above where I make the same call
var start_one = ds_list_find_value(global.opponent_card_list,0);


var start_two = ds_list_find_value(global.opponent_card_list,1);
var start_three = ds_list_find_value(global.opponent_card_list,2);

var ytsart = top_line_opp_draw.y+16;
//create the initial 3 cards 
instance_create_depth(left_line.x-72,ytsart,-1000,start_one);
instance_create_depth(left_line.x-72,ytsart+64,-1000,start_two);
instance_create_depth(left_line.x-72,ytsart+128,-1000,start_three);

Does anybody have any ideas as to what is going on here?
Sometimes I feel like I am eating crazy pills.
 

Relic

Member
Do a search for global.opponent_card_list from the edit menu and look for reasons why this variable could have been overwritten or its list destroyed.
 

Pfap

Member
Here the search output is.
Code:
handle_setup at line 101:  global.opponent_card_list = ds_list_create();
handle_setup at line 103:  ds_list_add(global.opponent_card_list,ds_list_find_value(card_net_list,0));
handle_setup at line 104:  ds_list_add(global.opponent_card_list,ds_list_find_value(card_net_list,1));
handle_setup at line 105:  ds_list_add(global.opponent_card_list,ds_list_find_value(card_net_list,2));
handle_setup at line 116:  //show_debug_message("ds_list_find_value(global.opponent_card_list,0)");
handle_setup at line 117:  //show_debug_message(ds_list_find_value(global.opponent_card_list,0));
opponent_cards-Destroy at line 5:  //ds_list_destroy(global.opponent_card_list);
opponent_cards-Create at line 7:  var start_one = ds_list_find_value(global.opponent_card_list,0);
opponent_cards-Create at line 8:  var start_two = ds_list_find_value(global.opponent_card_list,1);
opponent_cards-Create at line 9:  var start_three = ds_list_find_value(global.opponent_card_list,2);
Search Complete (10 results)
I'm really not sure what is going on... maybe it is some weird behavior from reading a list into another list? My project is kind of a mess and I really can't submit any useful kind of bug report from what I have, but I switched to using a global array and I got my desired output.
 
I would guess that when you ds_list_destroy(card_net_list) you destroy the DS that the global.opponent_card_list is pointing to and that causes an error. Try removing that line and see if the error still pops.
 

Pfap

Member
I would guess that when you ds_list_destroy(card_net_list) you destroy the DS that the global.opponent_card_list is pointing to and that causes an error. Try removing that line and see if the error still pops.
Just tested that and the problem still remains.
Although, after playing around some more think I did something in the http event awhile ago where I had a similar issue that I couldn't use lists if I was reading network data from JSON decode. The list I'm destroying in the script above ds_list_destroy(card_net_list); is an array I am receiving from my server. So, I never actually created the card_net_list in gamemaker, but got it like this

var card_net_list = ds_map_find_value(message,"sendCards");

It works well as long as I remember in the future to use arrays when receiving network data and it seems pretty stable.
 
Yeah, saving and loading from the json functions can play around with how the data is perceived by GM. I'd say that some experimentation is in order (try creating a ds_list for the card_net_list before populating it, as a start).
 

Pfap

Member
Yeah, saving and loading from the json functions can play around with how the data is perceived by GM. I'd say that some experimentation is in order (try creating a ds_list for the card_net_list before populating it, as a start).
I'll stick with arrays, but are you saying do something like this.

Code:
//the array I'm recieveing looks like this [ 1,2,3,4,5,6 ]

var card_net_list = ds_list_create();


//ds_map_find_value(message,"sendCards") holds the array [ 1,2,3,4,5,6 ]
var card_net_list = ds_map_find_value(message,"sendCards");
I'm not sure how that would work, it doesn't make sense to me, but I could play with it.

Edit:

Hmmm, I just checked the manual for ds list add and they show this:
Code:
ds_list_add(id, val1 [, val2, ... max_val]);
I'm actually really curious now as to what a ds_list actually is as they have the brackets in the official syntax section.

Maybe, you are right and I need to do:

Code:
ds_list_add(  card_net_list, ds_map_find_value(message,"sendCards")  );
 
Last edited:
Are you marking card_net_list as a list (ds_map_add_list rather than just ds_map_add) before you encode it into json? It won't save the data properly if you aren't. (Also, yeah, what you said above won't work, that's why I said populate instead of simply copy ;) ).

If I were a betting man, I'd say that you're probably doing something like accessing global.opponent_card_list as though it were an array at some point, instead of a ds_list, which would stop it being a ds_list and therefore cause the error you're talking about.
 
Last edited:

Pfap

Member
Ok, that actually makes a lot of sense I'll have to work on changing everything over. I was actually saving it in the ds_map as an array...
Thanks for helping, knowing that should make my life easier :)

Edit:

Lol, maybe you should become a betting man...
 
Top