ID:149736
 
I'm making objs likes carts, bags, etc. Which can hold other objects. I've got the part working where I can move objects from usr.contents -> src.contents and the src can be picked up and carried by usr. My problem is getting the objects out of the src and placing them at usr.loc or src.loc. Anyone know how I can do this? The code below is the take out object code I have now.

LJR


Take_Out()
if(contentst.len == null)
usr << "There are no bricks on this cart."
return
src.Move(usr.loc)
usr << "You take a brick off the cart."
I'd use something like this:

obj/cart/verb/TakeOut(obj/O as obj in contents)
if(O.Move(usr)) // or usr.loc/src.loc
usr << "You take \a [O] from \the [src]."
else
usr << "You cannot get \the [O]!"
In response to Foomer
Don't forget

set src in view(1)

or you'll have to pick up the cart to get anything out of it. ;)
LordJR wrote:
if(contentst.len == null)
usr << "There are no bricks on this cart."
return
src.Move(usr.loc)
usr << "You take a brick off the cart."

Your trouble is in two places:

  • contents.len is a number, so null is not appropriate for comparison (even though it would probably work); use 0. Or, just use if(!contents.len) instead.
  • src.Move() is moving the cart, not a brick, because src is the cart.

    To handle that second problem, try this:
var/obj/item=contents[1]
item.Move(usr.loc)
usr << "You take \a [item] off [src]."

Note that this code is generic, so if the cart holds more than just bricks, that will work too.

Lummox JR
In response to Shadowdarke
And what's wrong with that!? :oP
In response to Lummox JR
Thanks guys.. Foomer's code worked fine for what I'm using it for and your suppose to have the cart in your inventory to use it so thats find. But I'll use Shadow's code later when I make boxes and chest to put items into. Now I need to make my bags works, where that code for multiple items will come in handy! :)

LJR