This is something that's been bugging me for a while. It seems that WriteVerb
would be a little more useful if it had some context for what has been said before. (For example, knowing whether to refer to an object by its pronouns or alias).
So how about:
<function name="WriteVerb" type="string" parameters="obj, verb">
return (CapFirst(WriteNoun (obj)) + " " + Conjugate(obj, verb))
</function>
<function name="WriteNoun" type="string" parameters="obj, definite">
result = GetDisplayAlias (obj)
if (IsDefined ("definite")) {
if (defiinite) {
result = GetDefiniteName (obj)
}
}
if (not HasAttribute (game, "lastobjects")) {
game.lastobjects = NewObjectList()
}
if (ListContains (game.lastobjects, obj)) {
filtered = FilterByAttribute (game.lastobjects, "gender", obj.gender))
// Use "he", "it", etc sensibly depending on its position in lastobjects
// Either it's the only object of its gender mentioned in the command, or it's one of the last two objects mentioned
if (IndexOf (game.lastobjects, obj) + 2 >= ListCount (game.lastobjects) or ListCount (FilterByAttribute (game.lastobjects, "gender", obj.gender)) == 1) {
result = obj.gender
}
}
// Move the object to the end of lastobjects
while (ListContains (game.lastobjects, obj)) {
list remove (game.lastobjects, obj)
}
list add (game.lastobjects, obj)
return (result)
</function>
I think that should mean that if you do something like:
msg (CapFirst(WriteVerb(bob, "eat") + " " + WriteNoun(cake, true) + "."))
for a command that can be phrased in several ways, you could get output like:
==> give cake to bob
He eats it.
==> drop cake
Bob eats it.
==> feed bob
He eats the cake.
If you tweak other parts of the game, like FormatObjectList
, to use a function like this, it could make it more convenient to output text. Having the output system come out with "He" or "Bob" automatically, depending on if Bob was the last person mentioned. This could be especially useful if you have quite complex text in the text processor, with many optional or random parts.