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

Legacy GM [solved] Difference between ds_list_add and ds_list_set?

W

Wild_West

Guest
I just started working with ds_list and I'm looking through the functions but I don't get what's the specific practical use of ds_list_set compared to ds_list_add.

It says if you use set to put a value in the list outside the size of the list, it'll just create the indices needed to reach that position. So is it just like making a big blank list without having to use ds_list_add for all of them?

Or is there anything else it'd be used for as something specific that ds_list_add can't do?
 

Neptune

Member
With 'ds_list_set', you could change a particular pre-existing cell, like whatever is in position 3:
Code:
ds_list_set(list,2,"something");
'ds_list_add' always just makes the list larger by 1.

These would be the same (increasing the list size with a new value... Ive never used ds_list_set in this way though):
Code:
ds_list_set(list,ds_list_size(list),"something");
ds_list_add(list,"something");
Alternatively, you can use the accessor syntax for lists like so:
Code:
var value = list[| 2];

list[| ds_list_size(list)] = "something";
I like to use accessor syntax wherever possible, so you avoid all these wordy function calls.
 
Last edited:
W

Wild_West

Guest
With 'ds_list_set', you could change a particular pre-existing cell, like whatever is in position 3:
Code:
ds_list_set(list,2,"something");
'ds_list_add' always just makes the list larger by 1.

These would be the same (increasing the list size with a new value... Ive never used ds_list_set in this way though):
Code:
ds_list_set(list,ds_list_size(list),"something");
ds_list_add(list,"something");
Okay but what about ds_list_replace? doesn't that sound the same?
 

Neptune

Member
As you can see, the short-hand syntax does the job of all these weird functions. I'm not sure why you would use 'replace' vs 'set' though.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
As you can see, the short-hand syntax does the job of all these weird functions. I'm not sure why you would use 'replace' vs 'set' though.
Much like ds_map_replace, ds_list_replace will not replace items that do not exist (in this case, due to being past the list size).
 
W

Wild_West

Guest
As you can see, the short-hand syntax does the job of all these weird functions. I'm not sure why you would use 'replace' vs 'set' though.
so it's mostly just like with speed vs hspeed and vspeed then I guess. Okay thanks.
 
Top