Hello! I’m trying to write a game about magical transformations, where the player’s identity is fluid to some extent. Obviously, this involves a lot of special casing. To make my life easier, I’d like to achieve the following functionality: whenever square brackets appear in any output text (whether it be room/object descriptions, response text to actions, anything), I’d like to check a substitution list and replace the text in square brackets.
For example, a room description might read:
“You stand outside Castle Grimdark, Count von Cliche’s lair. Your knees tremble in fear.”
… but that’s no good, because the player might be a slug, or a ghost, or a treant! Possibly no knees, possibly not even standing. So what I’d like is to be able to have this as the room description:
“You [stand] outside Castle Grimdark, Count von Cliche’s lair. [Your knees tremble] in fear.”
And then I’d like the game to check a substitution list to see if the strings “stand” and “Your knees tremble” should be replaced with anything. Maybe the player is a ghost, and the substitution list has the pairs: “stand”, “float” and “Your knees tremble”, “Your ectoplasm shivers”. I’d like the parser to find these and replace the text accordingly, so this is what the player will see:
You float outside Castle Grimdark, Count von Cliche’s lair. Your ectoplasm shivers in fear.
Again, I’d like this functionality to be available for all game text, not just room descriptions. What’s the best way to intercept and mess with output text? I’m using Web UI TADS 3.
You should probably look on the OutputFilter functionality. It’s a class made for such transformations. Look for example on typographicalOutputFilter object defined in en_us.t which transforms some typographic characters in output text. When you define your own filter inherited from OutputFilter class, don’t forget to register it to the particular output stream(s). Search through the Adv3 library source codes for addOutputFilter method calls to notice how and where they are registered.
Perfect, thank you! God I love this language, I wish I had tried it earlier instead of wasting weeks desperately trying to make Quest5 do things it didn’t want to.
Just for the record, Quest has an output filter as well for all game text.
However doesn’t TADS (and Quest too for that matter) also have a simpler substitution mechanism similar to Inform 7’s 's ? I thought TADS got it with the latest release.
I was thinking of other stuff I was trying to do, but I realize I might have sounded inflammatory, and I just want to clarify that my troubles with Quest were more likely due to my own incompetence than any fault in Quest. I’m a Java programmer and the way TADS works just feels more natural and comfortable to me. I meant no disrespect!
You probably mean embedded expressions. They are a way to embed some code directly into a text. For example: “The door <<isOpen ? “stands open” : “is firmly shut”>>.”; They allow to insert a variable or call a function to produce changeable output and with ability to define custom embedding syntax with string templates it could probably produce similar effect. See http://www.tads.org/t3doc/doc/sysman/strlit.htm. But output filter seems to me more straightforward to do replacement based on table.
I was going to suggest using embedded expressions that call a function (or call a method on the player object) that returns some text. I’ve never used output filters, so I personally would head straight for the embedded expressions.