ID:264450
 
Code:
//Here is our object:

obj
Plaything
desc = "Toy for trying out verbs. Tastes like white chocolate."

//Here is the login code, which places the object in usr.contents.
mob
Login()
Move(locate(/area/Lounge))
new /obj/Plaything (usr)

//Here are the drop, get, look, and inventory verbs.
drop(var/obj/O in usr.contents) //drops an item at your position
Msg23("You drop [O].","[usr] drops [O].")
O.loc = usr.loc

get(var/obj/O as obj in oview()) //picks up an item at your position
Msg23("You get [O].","[usr] gets [O].")
O.loc = usr.contents

inventory() //checks your inventory
usr << "You are carrying:"
for (var/obj/O in usr.contents) usr << O

look()
var/area/A = loc
if(istype(A))
A.look(src)


Problem description:

You can look at the Plaything when you spawn, and it appears in your inventory. However, upon dropping it and then picking it up again, it will not appear in your inventory, nor does it remain in the room; it just 'vanishes'.

A little help here, please, because I have no goodly idea why.
Axel Wildfire wrote:
O.loc = usr.contents

[link]
In response to Kaioken
... I'm sure that would be helpful if I had any idea what you were talking about. xD; explanation, please?

(Also, sorry for the necro, but I've been out of contact with the net for weeks.)
In response to Axel Wildfire
instead of O.loc=usr.contents, use...

O.Move(usr)
In response to Dan0971
or you could use, (since it's a verb emanating from the mob)


o.loc= src.contents

or

o.Move(src)


unless you want to define a client in a procedure that doesn't involve the client or mob, NEVER use usr.

usr is only good if the verb or proc belongs to the item and you want to quickly define the client or mob that's affecting it.

If the verb lies with the mob itself, use src to define the mob.
In response to Dan0971
O.loc=usr.contents == O.Move(usr)

While many people do just move something to usr, moving it to usr.contents will achieve the same outcome. Also: while considered safer to use Move(), setting an atom's location directly (as our friend here is doing), works fine as well.
In response to Axel Wildfire
Delightfully, everybody in this topic completely missed the obvious error that was pointed out in the first reply. Oh well.
Note that it would indeed be better to use Move(Location) instead of setting loc directly to the new location, but that's not the main issue here.

Axel Wildfire wrote:
explanation, please?

Read it again until you get it? To break it down, you're trying to set loc to contents, which is a list. If you look up loc in the DM Reference (F1 in Dream Maker), you'll see that it's supposed to contain a location. A list is NOT a location, setting loc to any list is wrong.
For your information, a location is any atom (look this up in the Ref), or null (which means, well, no location). So a mob or a turf is a location, but not its contents list, which is a... list.
In response to Kaioken
thought i was solving two in one? and my code would have worked to because i didnt tell him to use O.Move(src.contents)
just O.Move(src)

well, i used usr before, but wasn't paying much attention before where the code was being called from...