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

trying to learn ds lists

F

fxokz

Guest
Is there a good way to learn how a ds_list works? I just read through the manual but it seems extremely confusing since you cant visually see the list that you create. or atleast that's what I think. I know its similar to a 1d array but is more flexible and all

The thing that confuses me the most about ds lists is that with an array you can see what the values are for example
Code:
array[0] = 10;
array[1] = 55;
etc etc but you cant with a ds list?

Its either I'm stupid or the manual is confusing. someone help xddd
 

Coded Games

Member
The code you wrote is the equivalent to this using ds_list:

list = ds_list_create();
ds_list_add(list, 10);
ds_list_add(list, 55);

Then you can modify the list with things like ds_list_insert, ds_list_shuffle and ds_list_sort. That is the main advantage to ds_lists over basic arrays.

Also after you are done with an ds_list you need to use ds_list_destroy to remove it from memory.
 
F

fxokz

Guest
The code you wrote is the equivalent to this using ds_list:

list = ds_list_create();
ds_list_add(list, 10);
ds_list_add(list, 55);

Then you can modify the list with things like ds_list_insert, ds_list_shuffle and ds_list_sort. That is the main advantage to ds_lists over basic arrays.

Also after you are done with an ds_list you need to use ds_list_destroy to remove it from memory.
Makes much more sense now but how would i refer to a position in my ds list?

In my array i know that array[0] is equalled to 10. There isnt a variable in a ds list that tells me what 10 is.
 
S

Salvakiya

Guest
list = ds_list_create();
list[|0] = 10;
list[|1] = 55;

using | the character just above enter on a US QWERTY keyboard you can use accessors to find the data you want just like in an array. for further information search the GM help manual for accessors.

you STILL have to destroy the list when you are finished though!
 
P

ParodyKnaveBob

Guest
Fwiw, to add to the discussion, you can also write...

Code:
ds_list_add(list, 10, 55);
...and...

Code:
ds_list_find_value(list, 0); // which returns 10
ds_list_find_value(list, 1); // which returns 55
...and even...

Code:
ds_list_find_index(list, 10); // which returns 0
ds_list_find_index(list, 55); // which returns 1
Oh yes, you can most certainly go to your list's positions to find its values. Even vice versa, which you can't do in an array! $E^ J

Also fwiw, I prefer putting a space after DS accessors for easier reading:

Code:
list[| 0] = 10;
some_var = list[| 1];
I hope this helps,
Bob $:^ J
 

TheouAegis

Member
If you use accessors, then you can view your list code the same way you view array code. However if you use the ds_list_add() method, then no you can't easily see what the positions are. But then, why would you need to? Why does it matter what you see? What matters is what the computer sees, and the computer sees 0 is 10 and 1 is 55.

Now suppose you want to increase the size of your array or list. Suppose instead of just 10 and 55, you want to append 120 and 183. With an array, you need to know ahead of time what indexes to write 120 and 183 to. With a list, you don't need to know, you can just add them in and GM will handle the indexing for you.
 
Top