ID:167894
 
Is it possible to search the associated values in a list without having to run through each main value? For example you have a list for equipment:

Equip = list("Weapon" = blah1, "Weapon2" = Blah2, "Armor" = Blah3)

How would be the best way to find out if Blah4 was an associated element in the list without cycling through Equip[Weapon], Equip[Weapon2], Equip[Armor].
I'm not quite sure I understand, because that is the way you access the association.

You can access element number 4 by going:

var/T = Equip[4]
var/T2 = Equip[T]
if(T2)
world << "This is an associative element!"

If you're saying you don't want to manually go through each one of those, and wanted to check other parts of the list as well, a for() loop would be in order:

for(var/i = 1,i <= Equip.len,i++)
var/T = Equip[Equip[i]] //Does same thing as above
if(T)
world << "This is an associative element!"
In response to Kunark
Alright, thank you. I think the second option you posted will work for what I am trying to do.
I was looking for a simple syntax such as how "in" is used for normal lists.
ex:
if(blah in list)

--Edit
I made a proc using the second option and I got it to work.
Thanks again!

proc
Search_Assoc(obj/item/O,list/L)
if(L.len && O)
for(var/i = 1,i<=L.len,i++)
if(O == L[L[i]]) return 1
return 0
In response to Drumersl
Why not if(l) for(var/k in l) if(l[k]==whatever)...?
In response to Jp
They do the same thing, so why not?

I think the number format looks better and he just gained one more bit of knowledge he might've neded later. Also, that may not be his entire procedure, or it may just be another procedure from a tree of them.

Just testing purposes or because it looks better, I suppose.