• 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!

Problem with ds_list

B

Bonemarrow

Guest
So, few hours ago I asked a question about arrays, and folks told me it would be easier to do it with ds_list. So here I am, stuck with ds_list. :)
In short, I have an array with all the owned items (Their ID's). Its called inventoryItemListTemp.
The plan is to store all items from the array to the ds_list, remove the desired item from the list, and then write all the item ID's from the list to one file, seperated with comas.

Example of my code:
Code:
item = argument0;
to_remove = 0;

list = ds_list_create();
//assign to the list
for(i=0; i<inventoryItemAmount; i++) {
    ds_list_add(list,inventoryItemListTemp[i]);
    if inventoryItemListTemp[i] = item then to_remove = i;
}
//remove the item from ds list
ds_list_replace(list,to_remove,"undefined");

//remove one item from var
inventoryItemAmount --;

inventoryDataS = file_text_open_write("InventoryData");
for(wr=0; wr<=inventoryItemAmount; wr++) {
    if ds_list_find_value(list,wr) != "undefined" then file_text_write_string(inventoryDataS,string(ds_list_find_value(list,wr))+",")
}
file_text_close(inventoryDataS)
Now the problem is, when the values from the ds_list are written to a file, the wrong item is removed.
For example, I load numbers 2,3,4,5,7 to the list. I remove the number in 3rd place. I write it to the file. However, the wrong number is removed.

In advance- thank you.
 
this seems like a convoluted way of doing something that should be simple. You should probably stick to using either an array or a list, but not both. I'm assuming someone suggested using lists becuase then you can convert the list to a string, which you can read and write to a file easily. Instead of adding an undefined, why don't you just remove the item from the list? If you stick to using an array, you can just replace the item with some "empty" value like -1. And in that case I don't see why you would need to avoid writing empty slots to file.

You say the wrong item is removed, which wrong item is removed? I'm going to guess it is either the first or last item in the list.
 
Top