• 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 [Solved] Correct way of restoring original values of list?

Biosyn

Member
I've gone through the manual but I wasn't successful in figuring out the correct way of refilling a ds list with its original values.

Suppose I have object Bob and Bob starts off with say, 3 apples 2 bananas, 1 cherry. I'd like to make it so that when all fruits have been used up (using ds_list_delete) Bob again gets 3 apples, 2 bananas, 1 cherry. I thought the copying functions might work, but nothing happens.

Here is what I have:

Create Event:

Code:
fruit_list_source=ds_list_create();

//Bob
ds_list_add(fruit_list_source,
app,
app,
app,
ban,
ban,
chr,
)

fruit_list_main = ds_list_create();
ds_list_copy(fruit_list_main, fruit_list_source);
;
Key Press Event:

Code:
if ds_list_size(fruit_list_main)>0
    {ds_list_delete(fruit_list_main,0)}
    else
    {   
    ds_list_destroy(fruit_list_main);
    fruit_list_main = -1;       
    
    fruit_list_main = ds_list_create();
    ds_list_copy(fruit_list_main, fruit_list_source);
    }
Thank you in advance.
 

Slyddar

Member
Your code works when I tested it. chr is a reserved word though, so I changed it to che, and made sure I had assigned variables to the values of app, ban and che (0, 1, 2).
At the end of your keypress event, you can use a script to show the output of the ds_list.

I wrote this one, which works well.
Code:
/// @desc ds_list_out();
/// @arg item

//takes input of ds_list and outputs it to console window
var _ds = argument0;

if ds_exists(_ds, ds_type_list) {
    show_debug_message("DS_LIST Output : ");
    for (var i = 0; i < ds_list_size(_ds); ++i) {
        show_debug_message(_ds[|i]);
    }
}
 

Biosyn

Member
I tried using the example variables with the fruits and it seems to work now. Strange. Not sure what the problem was, maybe there was some issue with the actual variable names.

And thanks for that script! Just added it to my project.
 
Top