Replacing text similar to a pig latin function?

I’ve been trying to get a translation system working in Inform that essentially would take arbitrary text and “translate” it as appropriate. In my case, I want it to turn into a form of gibberish, but once a player knows how to translate it, the same text isn’t transformed. As a simple example:


The library is a room.
The book is in the library.

Instead of examining the book:
	say "You read the book: [pig-latin]Really interesting stuff.[end pig-latin]"

Then there would some process to define the “how to do pig-latin” or some such. If the player was fluent, it would return the text as it was written, but if he/she wasn’t it would transform the text and return the mashed up variant.

Is this functionality available in inform? I haven’t seen any ways to define new start and end tags like the [if] and [end if] tags. Alternately, is there a better way to get to a solution for something like this?

Thanks!

25.27. Segmented substitutions is the manual page describing that. The following page as well. Inform 6 is needed, I believe.

However it looks like you’re wanting to “pass” the middle text to a function that prints a transformed version. I’m not sure how possible that is, but it sounds like a juicy little problem. This extension might also show you some tricks with Say-phrases that may or may not be helpful.

This is actually quite easy to do without any I6 or fancy say phrases; you just need the Text Capture extension. You’d set it up something like this:

[code]To say pig-latin:
start capturing text.

To say end pig-latin:
stop capturing text;
if the player understands pig latin:
say “[captured text][run paragraph on]”;
otherwise:
let T be indexed text;
let T be “[captured text]”;
replace the regular expression “\b(+)(\w*)” in T with “\1\2ay”;
replace the regular expression “\b(+)(\w*)” in T with “\2\1ay”;
say “[T][run paragraph on]”;[/code]

–Erik

That’s beautiful. I didn’t know anything about “start capturing text” - that solves things perfectly.

Thanks!