home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!asuvax!ukma!netnews.louisville.edu!wkuvx1!mollems
- From: mollems@wkuvx1.bitnet
- Newsgroups: rec.arts.int-fiction
- Subject: Re: counters
- Message-ID: <1992Nov20.104535.4117@wkuvx1.bitnet>
- Date: 20 Nov 92 10:45:35 CST
- References: <1992Nov20.071549.19959@nevada.edu>
- Organization: Western Kentucky University, Bowling Green, KY
- Lines: 50
-
- In article <1992Nov20.071549.19959@nevada.edu>, dalton@nevada.edu (William Turlough Cat) writes:
- > I need to be able to have an object count the number of times something is
- > done to it. Specifically, I want to be able to use something for a certain
- > number of times. I can't seem to find anything to do with counting except
- > in functions.
- >
- > William Turlough Cat aka beiad
-
- One possible solution to this (assuming you are using TADS, though the
- basic idea works no matter what you're doing) is to give the object an
- attribute called STATE. Then, each time it's used, the object's state
- is increased by one. For example, if you had a magic wand with three
- charges, which was used by waving it, you could do the following:
-
- magicwand : item
- noun = 'wand'
- adjective = 'magic'
- sdesc = "magic wand"
- thedesc = "the magic wand"
- ldesc = "The wand is really nifty; it's got lots of little
- stars and planets embossed on it, with some sharp gold trim.
- A label on the side of the wand proclaims it to be the
- \"Acme Dam Yooseful Magik Cheez (tm) Phrodukshun Devyse.\""
- state = 0
- verDoWave (actor) =
- {
- if (self.state = 3)
- "Waving the wand produces a tiny droplet of
- Cheez (tm), but nothing more.";
- }
- doWave (actor) =
- {
- self.state := self.state + 1;
- "You wave the wand, and the tip begins to glow
- brightly. Suddenly, there is a loud rushing noise
- which sounds like a freight train, and a torrent of
- Cheez (tm) comes gushing from the wand, covering
- everything in the area (including yourself).";
- }
- ;
-
- Thus, the first time you wave the wand, its state becomes one, the
- second time, two, the third time, three, and the fourth time it gets
- caught by the verDoWave potion of the item definition.
-
- Sean
- ---
- M. Sean Molley, CS Department, Western Kentucky University
- .sig is currently in the shop for 30,000 line tune-up and maintenance
-
-