Counting?

This may seem like a silly question, but how do you access the count property of the inventory?

Say I have 10 daggers in my inventory where each dagger is a copy of the dagger class, tads will say I have 10 daggers in my inventory if I pick up 10 daggers, but how do I access this property and get the number?

I’ve searched through the api, and I haven’t found the property name (I figured it might say like count or list or something).

Also, while we are here, how do you setup a static number (int) in your class? My work around was going to be to setup a static int in my dagger class and count them in the construct method.

Please and thank you :slight_smile:

Dunno about your first question … that number may be produced by the output mechanism at run-time, and then discarded immediately.

To the second question, if you look at the Object Definitions page in the System Manual, you’ll find that static is indeed a keyword in T3. Whether it will do what I think you want (create an int that can’t be changed during program execution?) is a question I can’t answer. I suppose the short answer is, if you don’t want it to be changed, don’t write any code that changes it. But that may not be an applicable approach in your case.

No, the static keyword doesn’t do what you want. What it actually does is initialise the property at compile time rather than run-time. It’s handy for certain pre-game bookkeeping that would otherwise have to run when the game starts, but doesn’t really get much use.

TADS 3 makes almost no distinctions between classes and objects, so you can create a count property on the Dagger class and then access it with Dagger.count, no differently than if you were using a property on an individual object. You just have to remember to always refer to Dagger.count, not to the count property of an individual dagger, in case they get out of sync.

To go back to Niobi’s original question: do you only want to count the daggers in your inventory, or do you want to know how many daggers there are in the whole game? Is there a fixed number of daggers, or can new daggers be generated during the game?

Oh cool, didn’t know there was no distinction like that. I should be able to use that to get the total dagger count, which is good. Thank you.

I would like to count the daggers in my inventory and how many there are in the game. I also intend to fix the number of daggers, but would like to be able to do this with a non-fixed number in the future.

Since tads already understands the number of daggers in my inventory, without my help, I should be able to access that number somewhere, right?

TADS doesn’t store the number anywhere, it just counts them on demand. It is little more complicated, to get an idea you should look at getListGrouping method in lister.t. This method is called from showList to figure the grouping of the items on the list (i.e. inventory) and then the showList calls showArrangedList to do actual listing which works recursively through any sublisters. One of the listers ListGroupEquivalent is then used to show the actual counted daggers in your inventory. The number is derived from the length of the list passed to the ListGroupEquivalent and this is determined above when the inventory is subdivided into groups.