Looping through text to replace individual letters

Hey all.

Using Inform 7 to work on my first full sized game. My background is in standard programming languages, and lots of them, so sometimes I just can’t get my head around a particular Inform 7 thing.

Basically, I am including your standard, but always fun, coded language into the game. You know the kind, like the D’Ni language in Myst - basically just a simple letter by letter replacement. No grammar or other ConLang madness. No thanks.

So what we’re talking about here is a replacement cipher, but with Unicode symbols. So, maybe A is ᚫ, and B is ᚰ, or whatever.

But, since copy-pasting Unicode symbols sucks, and encoding the text as these symbols in text means I wouldn’t know what I wrote in that text without decoding it myself…

Basically, what I need is almost a subroutine that takes regular text and replaces letters to this cipher. With another language, hey this is just an array, a loop, and a return from a subroutine.

But how might one implement this in Inform?

A table of roman letters and their replacement?

How do I loop through text one letter at a time?

I could imagine a simple Instead of examining… repeat… type loop, passing the description of the object, would work, but how would that actual loop look and how does one parse a text variable one letter at a time?

So, to sum it up: I would love to know how to take a text description of an object (like a piece of paper left in a desk) and dynamically turn roman characters into their replacement characters, so I can write the game in plain old English and leave the encrypting into this other “language” to the machine.

Any assistance, even pointing me to the right place in the docs, would be much appreciated.

Copying and pasting Unicode will be easier and faster than any other solution, actually.

Hmm, damn. Well, in that case I’m off to make myself a utility to do the “translation” for me for quick copy/paste of whole phrases. Guess I’ll just leave comments for myself in the Inform code to remind me of what the message actually says, so I’ll have an idea of what it is later.

Yeah, letter-by-letter processing is something Inform is not very good at. (Text in Inform games tends to be fairly static, so constant strings are compressed using various methods, and printing them is more like a routine call than C-style iterating over the letters.)

In your situation I’d write a quick-and-dirty Python script to convert the text. Something like:

translation = {
    'a' : 'something',
    'b' : 'something',
while True:
    txt = input()
    print('"{}" [{}]'.format(''.join(translation[i] for i in txt), txt))

Type in your text, get a translation in quotes and the original as an Inform comment. That’ll be far faster both in code-writing time and in running time than an Inform solution.

Wow, thanks. Saved me a bunch of time. Was just fighting with every language’s crap support of Unicode. For example, Lua has no support at all. And the Windows console? Nope.

But by running this snippet through IDLE (as the Windows console doesn’t print Unicode) I am able to get my translated substitutions followed by the comment. Well done, and thanks a million.

Just for anyone who runs across this in the future, if you’re using Python 2 it’s “raw_input()” instead of “input()”. Python 3, “input()” works.