ID:179754
 
I have my game setup where each mob has a series of lists that contain objs, and doing certain things adds certain objs to certain lists (yeah that clerifys it a lot). So anyway what i want to do is have a proc that searches through all the lists that belong to the mob and return all of them lumped together, so it would be like

proc/scanner()
completelist = list()
for(var/list()/L in mob/vars)
completelist += L
return completelist

only that code of course doesnt work so I need to know how id check for all lists that the mob uses. The reason for this is that each player has the option to start as a different mob and different mobs start with different lists, so i cant just search a set group of lists. So how would i do this?
Look up findtext() in the reference.
In response to Nadrew
Or don't, especially since it won't help at all. findtext() searches, quite expectedly, a text string. In BYOND text and lists are quite distinct.

What I would do is for each mob keep a list of what lists it uses. For example:

mob/example_mob
var/list/list1
var/list/list2
var/list/list3
var/list/list_of_lists = list("list1", "list2", "list3")

Then loop through list_of_lists like:
var/n
var/list/total_list
for(n in list_of_lists)
total_list += vars[n]

Something along those lines should do what you want.

[Edit:] I should add that each mob type would have a different list_of_lists. You could even dynamically create the list_of_lists based on other things about the mob.

-AbyssDragon
In response to AbyssDragon
AbyssDragon wrote:
Or don't, especially since it won't help at all. findtext() searches, quite expectedly, a text string. In BYOND text and lists are quite distinct.

What I would do is for each mob keep a list of what lists it uses. For example:

mob/example_mob
var/list/list1
var/list/list2
var/list/list3
var/list/list_of_lists = list("list1", "list2", "list3")

Then loop through list_of_lists like:
var/n
var/list/total_list
for(n in list_of_lists)
total_list += vars[n]

Something along those lines should do what you want.

[Edit:] I should add that each mob type would have a different list_of_lists. You could even dynamically create the list_of_lists based on other things about the mob.

-AbyssDragon


Ah, I see what you mean. I should have read the question a little better and I would have understood it better.
In response to Nadrew
Nadrew wrote:
Ah, I see what you mean. I should have read the question a little better and I would have understood it better.

If you'll forgive the observation, you seem to do that a lot. You partially read a question, then give a short answer that's wrong or doesn't apply at all. I'm sure people appreciate that you answer their questions, but if your answers are made so quickly that you never understood the question, it doesn't much help them.

Lummox JR
Skrylan wrote:
I have my game setup where each mob has a series of lists that contain objs, and doing certain things adds certain objs to certain lists (yeah that clerifys it a lot). So anyway what i want to do is have a proc that searches through all the lists that belong to the mob and return all of them lumped together, so it would be like

proc/scanner()
completelist = list()
for(var/list()/L in mob/vars)
completelist += L
return completelist

only that code of course doesnt work so I need to know how id check for all lists that the mob uses. The reason for this is that each player has the option to start as a different mob and different mobs start with different lists, so i cant just search a set group of lists. So how would i do this?

I think your code is actually close to what you'd use; there are just a few technical problems with it. AbyssDragon's approach, defining a list of lists at compile-time, isn't a bad one; the only significant drawback is that you could forget a list at compile-time and not notice until later, or accidentally leave one in (or misspell one) which would cause the same problem. To get your code to work, I suggest the following rewrite:
proc/scanner()
completelist = list()
for(var/L in vars)
if(istype(vars[L],/list))
completelist += vars[L]
return completelist

There's a drawback to this one, too, though: This will include every single list the mob uses, which might not be appropriate if you use lists for any other purpose. Fortunately I have a solution:
proc/scanner()
completelist = list()
for(var/L in vars)
if(istype(vars[L],/list) && findtext(L,"s_")==1)
completelist += vars[L]
return completelist

Now, all list vars that start with s_ (for "scan"), like s_inventory or s_attributes, will be included, but others won't be. It may be that you won't need this change, but it probably couldn't hurt to implement.

Lummox JR