intfiction.org

The Interactive Fiction Community Forum
It is currently Wed May 22, 2013 12:21 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Wed Jul 04, 2012 10:40 pm 
Offline

Joined: Sat Jun 30, 2012 4:31 pm
Posts: 10
Location: Calgary, Alberta, Canada
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.


Top
 Profile Send private message  
 
PostPosted: Thu Jul 05, 2012 4:51 am 
Offline

Joined: Tue Jan 22, 2008 5:55 am
Posts: 841
Location: The Netherlands
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:
Code:
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.)


Top
 Profile Send private message  
 
PostPosted: Thu Jul 05, 2012 6:00 am 
Offline

Joined: Tue Dec 25, 2007 10:06 am
Posts: 887
If decoding is an action that applies to a topic, you can use "topic understood".

Code:
Decoding is an action applying to one topic.

Understand "decode [text]" as decoding.

Carry out decoding:
   let message be indexed text;
   let message be topic understood;
   say message in upper case.

_________________
Vorple UI libraryBeta testing siteBlog


Top
 Profile Send private message  
 
PostPosted: Thu Jul 05, 2012 11:01 am 
Offline
User avatar

Joined: Fri Jul 15, 2011 2:46 pm
Posts: 230
Location: Cental Ohio
I probably wouldn't have written a decoder per se. I would probably have just changed the item's printed name to the decoded text, as if a key opening a door.

_________________
David Good
http://david-good.com/portfolio/interactive-fiction/
http://www.facebook.com/duodave


Top
 Profile Send private message  
 
PostPosted: Thu Jul 05, 2012 10:25 pm 
Offline

Joined: Sat Jun 30, 2012 4:31 pm
Posts: 10
Location: Calgary, Alberta, Canada
I really appreciate everyones help.
I'll be feeding the characters into the actual decoding or encoding algorithm one-by-one, so I need to be able to access each character individually.

The following seems to work in the way I need it to:
(Somehow the indentations for the Carry out... and repeat... are swallowed up by the webpage, but they are in my running code)

Quote:
"Test - Accessing individual characters of user input" by Geocacher

Home is a room. The cipher is in the home. "You see a cipher painted on the wall. It reads 'This is a test'."

Decoding is an action applying to one topic. Understand "decode [text]" as decoding.

Carry out decoding:
let cipher be indexed text;
let cipher be topic understood;
repeat with list-index running from 1 to number of characters in cipher:
let list-value be character number list-index in cipher;
say "([list-index]) is [list-value]";
say "."

and yields:

Quote:
Test - Accessing individual characters of user input
An Interactive Fiction by Geocacher
Release 1 / Serial number 120705 / Inform 7 build 6G60 (I6/v6.32 lib 6/12N) SD

Home
You see a cipher painted on the wall. It reads "This is a test".

>decode This is a test
(1) is t.
(2) is h.
(3) is i.
(4) is s.
(5) is .
(6) is i.
(7) is s.
(8) is .
(9) is a.
(10) is .
(11) is t.
(12) is e.
(13) is s.
(14) is t.

>

By the way, It was mentioned that renaming would work.
Could that be explained a bit more?
It sounds interesting and I'm always open to new ideas.


Top
 Profile Send private message  
 
PostPosted: Thu Jul 05, 2012 10:40 pm 
Offline

Joined: Sat Jun 30, 2012 4:31 pm
Posts: 10
Location: Calgary, Alberta, Canada
David;

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.


Top
 Profile Send private message  
 
PostPosted: Fri Jul 06, 2012 8:42 am 
Offline

Joined: Tue Mar 09, 2010 2:34 pm
Posts: 2128
Location: Burlington, VT
To preserve the tabs in your code, paste them into a "code" block rather than a "quote" block.

Code:
Every turn:
   say "If you pasted this into a code block, you'll be able to see the tabs.";
   say "If you pasted this into a quote block, you won't."


Quote:
Every turn:
say "If you pasted this into a code block, you'll be able to see the tabs.";
say "If you pasted this into a quote block, you won't."


Top
 Profile Send private message  
 
PostPosted: Fri Jul 06, 2012 11:03 pm 
Offline

Joined: Sat Jun 30, 2012 4:31 pm
Posts: 10
Location: Calgary, Alberta, Canada
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.


Top
 Profile Send private message  
 
PostPosted: Sat Jul 07, 2012 9:34 am 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 2085
Quote:
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.


This is true of 98% of all IF puzzles. I wouldn't get too worked up about it.


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group