ID:150406
 
If I do this

put(obj/O in usr)
O.loc = src:contents

as a way to put an object from your inventory into a container, how, then, do I a: display the items in the container to the usr or b: display the items in the container in the stat panel only when the container is open?
Kidknee wrote:
put(obj/O in usr)
O.loc = src:contents

First off, avoid using :. It is a very dangerous way, when your game gets bigger. Try to use . instead.

as a way to put an object from your inventory into a container, how, then, do I a: display the items in the container to the usr or b: display the items in the container in the stat panel only when the container is open?

A) Use Stat(). Here's an example.
mob/Stat()
statpanel("Inventory",src.contents) //arg 1 = name, arg 2 = what it'll contain


B) Use an if() in Stat()
mob/var/bagopen = 0 //starts closed
mob/verb/openbag()
bagopen = 1
usr << "You open your backpack."

mob/Stat()
if(bagopen == 1) //if they've opened their bag
statpanel("Inventory",src.contents) //show it's contents
In response to Vortezz
Yes, but the problem is, I intend on people being able to have multiple containers. I know to use if() in Stat(). I need to know how to identify a given bag within Stat(), and/or how to just list them to usr << src.contents.
In response to Kidknee
Make a list, bag, and a list, sack.

statpanel(bag)
statpanel(sack)


obj/verb/Put(obj/O in usr)
var/which = input("Where to put the [O]?") in list("Bag","Sack")
switch(which)
if("Bag")
O.Move(src.bag)
if("Sack")
O.Move(src.sack)

And such.

Good luck!
A couple of things.

One..... A lot of people are going to tell you this, (well hopefully not after me, if you've understood). The : operator doesnt need to be used here. You can call the contents simply by using . , as with : you HAVE to be 100% sure that nomatter WHAT the thing being called has the variable, or it will produce an error. It's just good to get into the habit of using . so that you wont make the mistake on something when your not sure if it has the variable or not

Two..... Look up the Move() proc, its usually a neater way to do this sort of thing, heres an example :

obj/verb/Get()
src.Move(usr)

calls the Move proc on src, and its destination is usr(since usr is the thing using the verb)

Now if you want to expand on this, you can do it without some extra work

obj/verb/Get(obj/O as obj in oview(0))
if(O.Move(usr))
else
usr << "You cant pick this up!"

If you call a proc inside an if statement, it will execute it if the proc returns a value thats NOT "",null or 0.

So in this case, the Get verb will let you choose an object your standing on to pick up. This way if there are multiple objects and some you dont want to pick up you can choose. If there is just one object it simply picks that one up.

Hope that helps, and that you do not copy the code from the post but try to understand how it works first.

Alathon