ID:156133
 
Ok, so. I've been wondering how to do this for a while.. How do I tell if a SPECIFIC object is in a list?
Basically, I have a garbage can system.. And often there will be identical objects in there, which causes problems, especially since it glitches if any of these objects are also on the ground.. I did:
Click()
if(src in usr.statpanels2)
if(isobj(src))
switch(input(usr,"Are you sure you want to take the [src]?") in list("Yes", "No"))
if("Yes")
var/obj/P=src
P.loc=null
usr.contents.Add(P)
if(usr.statpaneled=="can1")
global.can1-=P
usr.statpanels2-=P
else
return
else
return
else
return

But clearly that didn't work..
Some people may say "put this in Code Problems".. But I'm not asking for an error, because I know that there is no error, and that I'm just not doing it right. Basically, what happens is, if they are identical items only one will ever get added to the list, and if there is one on the ground.. Well, it gets really messed up.. So, please help, thank you!
Xyphon101 wrote:
Ok, so. I've been wondering how to do this for a while.. How do I tell if a SPECIFIC object is in a list?

if(X in list)


Or:

if(list.Find(X))



Your issue does not lie with BYOND magically making two objects into one. You've messed something up elsewhere, likely in populating the can1 list or the statpanels2 list.
In response to Garthor
If(src in list) checks if that src is in the list, yes, but right now it seems that it checks if an src by that name is in the list, not that src.

Like, it checks if "Pencil" is in the list, but it doesn't matter what pencil. I know this because if a pencil is on the ground, and I click on it while the statpanel is up and a pencil is in the statpanels2 list, it picks up the pencil.

There should be nothing wrong with my garbage can or statpanels2 lists, but I'll show you them anyway.

        CanFill()
var/obj/AppleCore=new/obj/AppleCore
var/obj/Paper=new/obj/Paper
var/obj/UnsharpenedPencil=new/obj/UnsharpenedPencil
//global.can1
var/CanRand=rand(1,5)
//Item1
var/CanRand2=rand(1,3)
global.can1-=global.can1
if(CanRand2==1)
global.can1+=AppleCore
if(CanRand2==2)
global.can1+=Paper
if(CanRand2==3)
global.can1+=UnsharpenedPencil
if(CanRand>=2)
var/CanRand3=rand(1,3)
if(CanRand3==1)
global.can1+=AppleCore
if(CanRand3==2)
global.can1+=Paper
if(CanRand3==3)
global.can1+=UnsharpenedPencil
if(CanRand>=3)
var/CanRand4=rand(1,3)
if(CanRand4==1)
global.can1+=AppleCore
if(CanRand4==2)
global.can1+=Paper
if(CanRand4==3)
global.can1+=UnsharpenedPencil
if(CanRand>=4)
var/CanRand5=rand(1,3)
if(CanRand5==1)
global.can1+=AppleCore
if(CanRand5==2)
global.can1+=Paper
if(CanRand5==3)
global.can1+=UnsharpenedPencil
if(CanRand>=5)
var/CanRand6=rand(1,3)
if(CanRand6==1)
global.can1+=AppleCore
if(CanRand6==2)
global.can1+=Paper
if(CanRand6==3)
global.can1+=UnsharpenedPencil
return


            Check()
set src in oview(1)
if(usr.Spectator)
return
usr.statpanels2-=usr.statpanels2
usr.statpanels-=usr.statpanels
usr.statpanels+=src
usr.statpanels2+=global.can1
usr.statpaneled="can1"
In response to Xyphon101
Hah.. I just realized I wasn't making a new object.. I've fixed it now, my mistake for not debugging enough, sorry for wasting your time.
In response to Xyphon101
You are adding the same object multiple times to the can1 list, but there's still only one object. It's just listed twice. As a result, when you remove one entry of it, you've already acquired the object, but it's still "in" can1.
In response to Garthor
Yeah, as you can see, I figured that out.. Again, sorry for wasting your time.