23 Feb, 2010, donky wrote in the 1st comment:
Votes: 0
donky said:
I've done a lot of Python programming, and that's the way I am expecting to go too.

"{0.name} is a {0.gender} {0.race}".format(actor)
However, unlike in your example, you cannot have arbitrary levels of depth in the formatting brace bits. But then you can just do:

"You're seeking the blarney stone? You'll have to find {0.name},
{0.pronoun_subjective}'ll know where it is.".format(faction.leader('Irish'))
Doing it this way will make it easy to cache fetched data in the local variables, for easy reuse in the string to be formatted.

Since I find myself writing lots of:

for ob in room.contents:
if ob is actor:
ob.user.Tell("first person message")
ob.user.Tell("third person message")
I thought it was the stage where I needed to implement a viewer dependent message interpolation system. Thinking about the approach I suggested above, when looking at applying it in my test cases, it didn't really work. In particular, the actor seeing the message refering to himself should see "you" instead of his short description. Also, when seeing the verb that he or she is doing, it should be in the grammatical form with no extra 's' for which I do not know the term. When a third party sees the verb that the actor is doing, they should see it in the grammatical form with an extra 's', or whatever differences are relevant depending on the verb perhaps. It's been a long time since I thought about this sort of stuff.

Now, in the 'format' approach to string formating in Python, you can only go one level deep with attribute access. And it doesn't evaluate things like function calls, so I cannot do:

'{0.viewedShort(1)}'.format(actor, viewer)
So I made a proxy object that wraps the actor and the current viewer, and I have it recognise special attribute access on it, in a viewer dependent way. So I would go:

v = ViewedActor(actor, viewer, "say")
The following initial attributes are supported:
  • v.s: If the actor is the viewer, gives "you". Otherwise, gives the actor's short description with its existing capitalisation.
  • v.S: If the actor is the viewer, gives "You". Otherwise, gives the actor's short description with its existing capitalisation.
  • v.v: If the actor is the viewer, gives "say". Otherwise, gives "says".

  • Some examples in use which work:

    # The "say" command.
    info.room.Message("{0.S} {0.v}: {1}.", (info.body, info.verb), string)
    # The "take" command.
    info.room.Message("{0.S} {0.v} {1.s}.", (info.body, info.verb), ob)
    Code: room.py

    One thing that would be useful, is knowing the common cases which a messaging system like this needs to handle. It has been too many years since I worked on text-based code like this, and I have forgotten any knowledge I might have had. I do recall that the Lima LP mudlib had handling like this, although I have ben unable to find it.

    Anyone know of any previous discussions on that topic? Or of documents that list syntax accepted to a similar function?
    23 Feb, 2010, David Haley wrote in the 2nd comment:
    Votes: 0
    There have been discussions about language and grammar here, although I'll confess that a very cursory search didn't find them and at present I'm too lazy to look them up. But yes, there have been discussions about how one deals with a generalized, language-aware system that knows how to appropriately conjugate verbs based on the subject, knows how to get nouns and adjectives to agree, etc. – be it in English or in other languages.