ID:160768
 
How would I go about making code-efficient, but usr-friendly (as in very quick to access with only 1 button press) containers for my world? I never quite understood how to do this, and being out of the loop for a while fried my BYOND lobe in my brain D:

Thanks for the pointers/suggestions!
In response to Jemai1
I'm not trying to come off as rude, but I've been with byond for 4 years. I wouldn't have made any progress without those tutorials.

However, I don't think I've ever seen a container code or suggestion in any of them, unless it's in a new one.

Once again, not trying to sound rude, but give me just a slight bit more direction than that. Or a practical application of something I missed that could be used?
Pakbaum wrote:
How would I go about making code-efficient, but usr-friendly (as in very quick to access with only 1 button press) containers for my world? I never quite understood how to do this, and being out of the loop for a while fried my BYOND lobe in my brain D:

What on earth does "containers for [your] world" mean? If you mean universal programming conceptual containers such as stacks and queues, look up hub://UnknownPerson.upContainers. If you're referring to something else, you have to understand that you can't just make up a word for something and hope that everyone knows what you're talking about---details are vital.
In response to Pakbaum
Well, I'm not trying to come off as rude either (and things tend to seem simpler after you know about them, I suppose), but this seems like quite a simple thing to do if you already know about DM (it's basically like programming a normal item Get() verb). For 'simple', see:
obj/container
/* extra info if needed/wanted
var
max_items
max_weight
*/

verb
Look()
set src in view(1)
usr << "You open [src]."
for(var/atom/A in src.contents) //the 'anything' part is so it doesn't filter by type check - it's unneeded as everything in contents is always an atom for granted (note can also use 'in src')
usr << "Inside you see \a [A]." //can include the icon if wanted with a quick \icon
Put_Into(obj/O in usr)
set src in view(1)
if(O.Move(src))
usr << "You put [O] in [src]."
Take(obj/O in src)
set src in view(1)
if(O.Move(usr))
usr << "You take [O]."

/* note: if verb arguments are unsuitable for one reason or another, you just use input(). it's generally a good idea to
verify the args on the start of the verb either way


That's the basic gist of it. I'm not sure if you wanted something more specific or different (or not), though. If that wasn't the example/thing you were after, then ask for whatever it is (since you weren't very descriptive, I had to take a guess). =)
In response to Kuraudo
...What? I never inclined that the containers in question were special or "for my world", just efficiently coded.
In response to Kaioken
No no, it's quite alright. The question was supposed to be somewhat vague anyways.

And I was thinking and remember any time I'd seen anything having to do with containers in the past, it was always list controlled. In all honesty, I didn't even think about obj's having -contents-. ><

Anyways, thank you for your help.

EDIT: Also, could you eleborate just a mite on the \icon bit you threw in there? I'd like to have just the icon for the items in question, if possible.
In response to Pakbaum
Pakbaum wrote:
No no, it's quite alright. The question was supposed to be somewhat vague anyways.
...What? I never inclined that the containers in question were special or "for my world", just efficiently coded.

What Kuraudo said, correctly, is that you were not very elaborate or detailed in your question. The only clue you've given to what you want is a single word, but that is vague and one can possibly mean different things by it, to 'outsiders'. Even if the basic point is able to be conveyed by a single word (I actually took a guess this time), it is customary to detailedly describe exactly what it is that you want, so the readers can get a better idea.

And I was thinking and remember any time I'd seen anything having to do with containers in the past, it was always list controlled. In all honesty, I didn't even think about obj's having -contents-. ><

Looks like you should look that list up. ;) All atoms (Areas Turfs Objs Mobs, incidentally) have that list, including turfs and areas, yes. It is tied into the movement/locatopm system. When you are standing on a turf, your mob is in that turf's contents list.
Also, mobs and objs aren't all that different. There are multiple differences, but not all that big, mainly extra vars like group,sight,client (of course, the client var is the largest difference - players can connect to mobs only).

It is possible to use a custom /list for this kind of things (ie inventory or whatever), however the contents list is suitable already, and more importantly it's generally more robust to use and tied into the movement system. This means you can already have a system (the movement system) at your disposal - the previous code example could be expanded like this:
obj/container/Entered(atom/A) //called when an atom enters our container
if(istype(A,/obj/bomb)) //if it's of a given type - could be used for multiple things
A.Explode() //trigger, or do whatever special thing you want
obj/container/Enter(obj/item/O) //called when something attempts to enter our container, and is used to determine if it should be allowed to or not
if(!istype(O)) return ..() //don't intercept non-item types
//this incorporates the previously commented-out vars
if(src.contents.len >= src.max_items)
return 0 //container is full, item-number wise
var/increased_weight = src.weight + O.weight //assumes you have 'weight' defined and used
if(increased_weight > src.max_weight)
return 0 //full, weight-wise
return ..() //do the normal decision, by default this is the same as 'return 1' to allow

//the next part is separated from above for robustness
obj/container/Entered(obj/item/O)
if(!istype(O)) return ..()
//a new object has entered the container, so its weight
//needs to be updated
src.weight += O.weight


EDIT: Also, could you elaborate just a mite on the \icon bit you threw in there? I'd like to have just the icon for the items in question, if possible.

Sure, but I'd like you to try to figure it out by using the documentation first, if possible. =P