[Reality] Socials questions

Glyph Lefkowitz glyph@twistedmatrix.com
Wed, 22 Mar 2000 15:15:27 -0500 (EST)


On Wed, 22 Mar 2000, Michael Dartt wrote:

> I'm parsing in the socials from a text file and storing them in a
> dictionary (Socials.socials, indexed by name, of course).  IIUnderstandC,
> I need to put an action() function in socials.py, which will be executed
> as if it were a verb.  Here's what I'm wondering:
> 
> 1) Since the socials are being held in their own dictionary, how will the
> game know to call the socials "verb" when someone calls, say, "bite"?  Or
> will "socials" be called whenever the given verb can't be found?

Socials is a regular verb; as such, its action method will be invoked when
it is found on an object.

I assume you're using a class for some of this stuff, so somewhere in
socials you'll have a line that looks like

socials=Socials("socials.txt")

You should, at least, have a module-global representation of whatever
object you're using to keep track of the socials you read in.

Then after that,

names=socials.getNamesTuple()

This will tell the core that your verb has the names listed in 'names'
(again, this has to be module-global).

> 2) Should I throw an InappropriateVerb exception or a NoVerb exception if
> the requested social doesn't exist?

InappropriateVerb; you really shouldn't ever raise NoVerb yourself.  
Think of InappropriateVerb as a NoVerb but giving the game an extra chance
to correct itself, if it somehow found your verb in error.

> 3) Should the action() method be inside the Socials class, or outside it?
> Is this true for all verbs?

It should be outside it.  The 'verb' is basically a module; you don't
*need* to define a socials class at all (although I can see how it might
be convenient).  The only things that the game will look for are a
module-global variable called 'names' and one called 'action'.  'names',
as I said before, should be a tuple containing the names that your verb
can be referred to as; 'action' should be a method which takes on
argument.

> I was thinking originally that the socials dictionary would be part of the
> given reality, e.g. self.socials = Socials("socials.txt"), and it could
> then be referenced by whatever does the verb checking, so that the socials
> stuff isn't run unless the requested one actually exists.

I don't think this would be a good idea, since it would negate the
benefits of being able to reload the socials module to reload the socials
file.

Also, socials shouldn't really have to be a 'special' verb... seems like
it would just add more crap to debug, without adding any functionality.

                      ______      __   __  _____  _     _
                     |  ____ |      \_/   |_____] |_____|
                     |_____| |_____  |    |       |     |
                     @ t w i s t e d m a t r i x  . c o m
                     http://www.twistedmatrix.com/~glyph/