ID:2381354
 
(See the best response by Kaiochao.)
Code:


Problem description:
I never really did use these, or have any reason to until now. Usually the order of things in a list really didn't seem to matter much. I don't really get how to use them, it looks like they have to be used with an actual number of that object's place in the list.

Is there a quick, easy way of figuring out what an objects place in the list is, or a mob's for that matter? It seems to me like these were not even meant to be used with a list containing mobs, but it would be nice to be able to.

What I want to do is put a mob that is not in the list at a certain position in the list, and remove the one currently at that position from the list. Sometimes it would be a group of mobs, rather than one single mob, that would be replacing that mob in the list.

Can somebody give a quick example please of how to do this? Like for example if the list is of objects that are actual mobs used in the world, and I want to replace the 2nd mob in the list with 3 other mobs that will each be placed before what is the 3rd mob in the list. I hope I said that right. lol

Best response
What I want to do is put a mob that is not in the list at a certain position in the list, and remove the one currently at that position from the list.
You can find the old mob's index with Find():
var old_mob_index = your_list.Find(old_mob)

To replace a single mob in the list, you can do this:
your_list[old_mob_index] = new_mob

Or, to remove it and then add a bunch of mobs starting from the old mob's index, you can use Insert():
your_list -= old_mob
// or
your_list.Cut(old_mob_index, old_mob_index + 1)

// then
your_list.Insert(old_mob_index, list_of_mobs)
Thanks Kaiochao. There is something else about lists I forgot to mention. Is there an easy way to see if a variable is a list? Like ismob, only for lists?
In response to LawnMower
Yep. You should already be declaring list-typed variables with the list type, so you should know that /list is a type. Since it's a type, you can use istype():
istype(whatever, /list)
Thanks again for helping me, I did run into a bit of a problem though, in a way its a bit of a problem. I might not be doing it right but insert seems to not be able to insert ascioated values. Is that true, or am I just using it wrong?
Set up the association on the next line.
In response to LawnMower
Oh, right. Associated values aren't kept when using Insert().

As MisterPerson said, you can remake the associations in the new list like so:
your_list.Insert(old_mob_index, list_of_mobs)

for(var/mob in list_of_mobs)
your_list[mob] = list_of_mobs[mob]