ID:1107483
 
(See the best response by Jemai1.)
In my project I have two lists to keep track of the teams of players:

blue_list[]
green_list[]


References to the player mobs are added and removed as players join or leave the teams.

My question is, if I want to frequently access the players in both lists, is it bad practice to add them together? Like this:

for(var/mob/M in blue_list + green_list)
M << sound('something.wav')


Is there any difference between this and writing a separate loop for each list?
By adding them, you'll create a new list. The process will allocate memory for that extra list.
Right...I think I'll just loop through each list separately
Best response
If you like, you can do it like this:
var/global/teams[2]
teams[1] = blue_list
teams[2] = green_list
for(var/i in 1 to 2)
for(var/mob/M in teams[i])
M << sound('something.wav')

We made the teams var global so it will be remembered next time we run the proc. By doing so, we avoided reallocation of memory and garbage collection.
I like that. Since I am also adding a spectator "team" it will make my code a lot cleaner if I do it that way :) thanks