I am trying to take some user input such as, “Decode qrytzh” and assign the “qrytzh” portion to an indexed text variable.
Can anyone provide a code snippet to show how this is done?
Inform7 sees “qrytzh” as being an object and not something one can use to set the value of an indexed text variable.
The assignment to an indexed text variable is needed, since I will be parsing the input string “qrytzh” in order to decode each character.
I think the easiest way to do this would be by running whatever indexed text operations you desire on the “player’s command” variable – which is, I think, already indexed text? The relevant part of the manual is section 17.31.
So something like:
After reading a command:
if the player's command includes "decode ":
now my-indexed-text is player's command.
and then you can cut "decode " away from my-indexed-text and you’ll be left with the phrase you want. (This is untested code, but I believe the basic principle is right.)
I think I understand what you were suggesting and appreciate your reply.
This occurred to me, but would only work for decoding.
This is because the author knows the plain-text that results from the cipher-text.
As part of the story, I may also have to encode an arbitrary message.
This could not be done the same way, since the author won’t know the encoded result of what the user has typed.
Why would I want to do that? Well that is a long story…
Suffice to say that I’m writing an IF adventure for geocaching and the group likes to play devious little tricks on each other in some of the puzzles we write.
And, I also wanted to learn a bit more about Inform7 indexed text by trying to write the code.
I actually think I’m starting to see how the language hangs together, but to really understand it will still take some time.
Thanks for the tip on posting the code. I’ll use the code block in future.
I should also mention another reason for not simply using an assignment to simulate decoding.
Doing so would mean that the plaintext would be stored in the code and decompiling would make it possible to crack the code without solving the puzzle.
By writing a decode routine, there is no way to determine the plaintext except by using the key or cracking the code.