ID:261783
 
Well, I have this very small problem with Opening a chest. Not liturally, but in code. It points to the second-last line. Anyone know what the problem is?

        OpenChest()
var/obj/chests/C
for(C in get_step(src,src.dir))
src << "You search the chest..."
flick("chestopen",C)
sleep(10)
if(src.chestsfound.Find(C.type))
src << "But there was nothing inside."
return
if(C.item == "Nothing")
src << "But there was nothing inside."
return
src << "And you have found \an [new C.item]!"
C.item += src
C += src.chestsfound


Thanks in advance

~~Dragon Lord~~
Unknown Person wrote:
src << "And you have found \an [new C.item]!"
C.item += src
C += src.chestsfound

You're completely mixing up your data types here. You're trying to add to things that you can't add to.

src << "And you have found \an [new C.item]!"

This implies that C.item is a type path, like /obj/item/sword. Earlier you checked against "Nothing", a text string, although I think null would serve you better. Nothing's wrong with this line though; it just establishes that C.item is a path, not an object or a string or a number.

C.item += src

You can only add things to a string, a number, or a list, and even then you can't add an object (src) to a string or a number, so this will fail. And fail it does.

I believe what you wanted to do here was just empty the chest, which with your current code you can do with:
C.item = "Nothing"
But I'd change that to C.item=null instead, and change "Nothing" earlier in your code to null.

Now, the last line:

C += src.chestsfound

C is an object, the chest, so you can't add to it. But I believe what you wanted to do was add this chest to the list src.chestsfound, which you can do by switching the operands around.
chestsfound += C

Lummox JR