ID:144195
 
Code:
item/parent_type=/obj //Not real code. Just what you need to know.
container
parent_type=/item
var
capacity
New()
..()
src.suffix="\[[capacity]\]"
Entered(item/I)
if(!istype(I)) return
if(src.capacity--)
src.suffix="\[[capacity]\]"
..()
Entered(item/I)
if(!istype(I)) return
src.capacity++
src.suffix="\[[capacity]\]"
..()


Problem description:
Things move okay, but the capacity does not increase or decrease.
try using src.capacity instead if just capacity
In response to A.T.H.K
Please don't try to give help if you don't know what you're talking about. capacity and src.capacity are equivalent in every respect.
Not sure what you're trying to do, here. I think that last 'Entered' should be an 'Exited'. Also, you probably want to set the suffix no matter what, so leaving it inside those if statements is probably a bad idea. In fact, I'd drop the if statements entirely - have Entered and Exited() change capacity, and then use Enter() to deny items entry to the bag if it doesn't have the room

container
Entered(item/i)
if(!istype(i)) return
capacity--
suffix="blah"

Exited(item/i)
if(!istype(i)) return
capacity++
suffix="blah"

Enter(item/i)
if(!istype(i)) return 0
if(capacity>=1) return 1 //Allow entry if there's enough room
return 0 //Otherwise, disallow entry. You can check whether something got in or not by looking at Enter()'s return code


EDIT: Fixed a minor typo.
In response to Jp
It's probably a better idea to use return ..() instead of return 1.
Also, you don't need 2 if checks in your Enter(), they should be combined.
<small>And you have a typo in your first ...is() check.</small>
In response to Kaioken
Kaioken wrote:
It's probably a better idea to use return ..() instead of return 1.

Nah, for a container, it should usually be 1. The default rule is to deny entry to more than one dense object like a mob, but an obj-based container should really need no such restriction. It's only turfs that need the rule, which is why it's the default; Move() isn't used much for managing mob and obj contents, so it's sensible to override the default if you're going to use it for that purpose.

Lummox JR
In response to Lummox JR
I don't think that default action actually applies for objs, I know it doesn't for mobs. So pretty much ..() is more robust, and if you don't have any override it will still return 1 anyway.
In response to Jp
Wow, what a fool I was. Thanks a lot. It works now :D
In response to LastTroubadour
No problem. You seem fairly clueful, and I don't have a problem with helping out someone that's trying to figure stuff out on their own.
In response to Kaioken
It's probably a better idea to use return ..() instead of return 1.

I would disagree. In the case of the container, if it can fit, you definitely want it in there. There's nothing gained by using ..(), except the danger that default behaviour might screw up something.

Also, you don't need 2 if checks in your Enter(), they should be combined.

They could be combined, yes, but for demonstrative purposes, it's clearer if those checks aren't stuck together. It makes what the code is doing a lot clearer.

And you have a typo in your first ...is() check.

Whoops. Good catch. :P
In response to Jp
Jp wrote:
There's nothing gained by using ..(), except the danger that default behaviour might screw up something.

The default behaviour just returns 1 if src isn't a turf, it seems, so no danger in that. If you happened to override atom/Enter() or somesuch, and you don't specifically want it not to run, you should go ahead and use return ..().