ID:263707
 
Code:
if(sinv_list[i] in sinv_selected)


Problem description:
I have 2 lists. One is called sinv_list and the other sinv_selected. Now I know that the exact same object exists in both lists. I am iterating through sinv_list and when I get to the object that I know is in both, the if statement above still evaluates to false. Is there any way around this? or am I maybe doing something wrong? I can post more code if it will help.
if(sinv_selected.Find(sinv_list[i])==1)

Try that, it is more exact, and I've noticed in only seems to look to see if something of that type is in the list.
In response to Tails5
Hmm, tried that with the same result. I also tried assigning the object to a temporary variable:

<code>
var/temp2=sinv_list[i]
var_dump_s(temp2)
showDebug("---------------------")
var_dump_s(sinv_selected)
showDebug(sinv_selected.Find(temp2))
</code>

I'm getting something like...

obj(/obj/equipment/weapon/gun/gun2) [0x200002c]
'damage' = "1d4"
'ammoclip' = 15
DEBUG: ---------------------

list
'Left Hand' =
obj(/obj/equipment/weapon/gun/gun2) [0x200002c]
'damage' = "1d4"
'ammoclip' = 15

DEBUG: 0

as the output.

Is it because the object uses an association string instead of an index?
In response to Neo Skye
Neo Skye wrote:
Is it because the object uses an association string instead of an index?

Yes, it appears that your first list has object references, and your second list has text strings, not object references, and those text strings are assossiated with objects. Although they are assossiated with objects, that does not mean that the object itself is in the list.

You are going to want to loop through the second list to see if the object is assossiated with anything in it.
proc/findAssossiation(list/targetList, find)
for(var/index in targetList)
if(targetList[index] == find)
return index
return 0

That will return 0 if not found; if the object is found, it will return the element assossiated with it (in this case, it will return "Left Hand")
In response to Loduwijk
That did it. Thanks guys I really appreciate it. I still think that the "in" keyword not catching the object being in the list is a bug in Byond, but I sleep safer knowing there's a workaround :)
In response to Neo Skye
Neo Skye wrote:
That did it. Thanks guys I really appreciate it. I still think that the "in" keyword not catching the object being in the list is a bug in Byond, but I sleep safer knowing there's a workaround :)

The object isn't in the list, and hence it's not a workaround. Assossiated data is not considered to be in the list.
var/list/L = list("this" = 10, "that" = new /obj, "the other" = "blah", /obj = "hi", new /mob = locate(1,1,1))

In that example, "this", "that", "the other", the /obj prototype, and an instance of a new mob are in the list. That is all the list contains. The list does not contain 10, any instances of type /obj, it doesn't contain "blah", "hi", or a reference to the turf at (1,1,1) - they are not part of the list.
In response to Loduwijk
Ah, well that makes more sense then. I'll definately have to keep that in mind in my designs. Thanks again, you've been a ton of help. :)