intfiction.org

The Interactive Fiction Community Forum
It is currently Sun Nov 19, 2017 11:09 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Text Capture by Eric Eve
PostPosted: Sun May 04, 2014 8:11 pm 
Offline

Joined: Thu Jan 28, 2010 3:57 am
Posts: 532
This topic is for discussions related to Text Capture by Eric Eve


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Jan 08, 2016 11:13 am 
Offline
User avatar

Joined: Sun Dec 23, 2007 3:24 pm
Posts: 188
This extension looks interesting, but I can't find it on the inform's website :(

http://inform7.com/extensions/all-exten ... y-title/#T


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Jan 08, 2016 11:18 am 
Offline
User avatar

Joined: Fri Jul 11, 2014 12:50 pm
Posts: 82
If I recall correctly, it is in the Public Library integrated within the Inform IDE (extension tab then small tab in the top right corner).

In fact since 6L38, it's better to look in the Public Library and the Github repo (github.com/i7) first.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Jan 08, 2016 11:21 am 
Offline
User avatar

Joined: Sun Dec 23, 2007 3:24 pm
Posts: 188
I don't use 6L38 (and the extension public search doesn't seem to work on linux), it was for an old game.
It was not longer listed no the website but I've found it, it's there: http://inform7.com/extensions/Eric%20Ev ... index.html

(I couldn't find it on github)

ps : you like owls too? ;)


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Jan 08, 2016 10:33 pm 
Offline
User avatar

Joined: Fri Jul 11, 2014 12:50 pm
Posts: 82
Yeah, it occured to me after I posted that you wanted a old version. I remember searching Text Capture on the Inform website without finding it.

(I like owls, but I sometimes regret it: they are more and more popular…)


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun Mar 20, 2016 5:01 pm 
Offline

Joined: Tue Mar 09, 2010 2:34 pm
Posts: 5115
Location: Burlington, VT
So I'd like to be able to adapt Text Capture to somehow recursively capture text. So you can have a phrase to "push the captured text stack" when you might be already capturing text, instead of throwing out the old captured text, it pushes it onto a list of texts and lets you continue capturing text into the text buffer. Which could easily be done by copying the captured text to a new variable.

And--this is the new part--you have a command to "pop the captured text stack" which loads the captured text buffer into "[captured text]" (just as "stop capturing text" does). Then, if there's anything on the stack of captured texts, refills the capture text buffer with the last thing the stack and continues capturing text into that buffer. If there's nothing on the stack, it stops capturing text.

So basically, I need a way of knowing how to copy something back into the captured text buffer so we can keep adding onto the end. How could this be done? Would it be a simple or simpleish I6 routine, if I knew I6?

An example might work like this:

Code:
To say start reversing:
   push the captured text stack.

To say finish reversing:
   let new string be captured text;
   pop the captured text stack;
   say "[new string in reverse]".

[and there'd be a routine for reversing a captured text]

When play begins: say "[start reversing]Foo[start reversing]bar[finish reversing]baz[finish reversing]."


Desired behavior:
You start reversing, pushing the captured text stack. If there were anything in the captured text buffer, it would get put on the stack. You also start capturing text into the buffer.
You say "Foo." This gets captured into the buffer, so the captured text buffer reads "Foo".
You start reversing again, pushing the captured text stack. So "Foo" moves from the captured text buffer to the top of the captured text stack.
You say "bar". This goes into the captured text buffer. So the captured text buffer is "bar" and the first element of the stack is "Foo".
You stop reversing. This loads the captured text buffer, "bar", into new string. Then it pops the captured text stack, which loads "Foo" back into the captured text buffer and continues capturing text. Then we say "[new string in reverse]", which is "rab", and since we're still capturing text it gets added to the end of the captured text buffer. So the captured text buffer is "Foorab" and the stack is empty.
Then we say "baz" which gets added to the back of the captured text buffer, so we have "Foorabbaz" in the captured text buffer.
Then we stop reversing again. This loads "Foorabbaz" into new string from the captured text buffer. Then it pops the captured text buffer, which since the stack is empty stops capturing text. So when we say "[new string in reverse]" it actually gets printed, and in the end we print "zabbarooF".

Anyway. Any ideas as to what I need to do to push things back from the stack into the captured text buffer?


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun Mar 20, 2016 6:43 pm 
Offline

Joined: Fri Oct 18, 2013 10:13 am
Posts: 2467
Location: The Midwest
The first place I looked is the "change the text of the player's command to" phrase, which effectively copies an I7 text into an I6 buffer (and then re-tokenizes it and such). The I6 definition (in 6L02) is:
Code:
[ SetPlayersCommand from_txt i len at p cp;
   cp = from_txt-->0; p = TEXT_TY_Temporarily_Transmute(from_txt);
   len = TEXT_TY_CharacterLength(from_txt);
   if (len > 118) len = 118;
   #ifdef TARGET_ZCODE;
   buffer->1 = len; at = 2;
   #ifnot;
   buffer-->0 = len; at = 4;
   #endif;
   for (i=0:i<len:i++) buffer->(i+at) = CharToCase(BlkValueRead(from_txt, i), 0);
   for (:at+i<120:i++) buffer->(at+i) = ' ';
   VM_Tokenise(buffer, parse);
   players_command = 100 + WordCount(); ! The snippet variable "player's command"
   TEXT_TY_Untransmute(from_txt, p, cp);
];


Trimming out a bit of the stuff we don't need gives
Code:
[ WriteBuffer from_txt i len at p cp;
   cp = from_txt-->0; p = TEXT_TY_Temporarily_Transmute(from_txt);
   len = TEXT_TY_CharacterLength(from_txt);
   if (len > 118) len = 118; ! Or whatever your maximum length is
   #ifdef TARGET_ZCODE;
   YOUR_BUFFER_HERE->1 = len; at = 2;
   #ifnot;
   YOUR_BUFFER_HERE-->0 = len; at = 4;
   #endif;
   for (i=0:i<len:i++) YOUR_BUFFER_HERE->(i+at) = BlkValueRead(from_txt, i);
   TEXT_TY_Untransmute(from_txt, p, cp);
];

This will put the specified text into YOUR_BUFFER_HERE. You'll probably also need to store how many characters you inserted (which is here the local variable "len") to offset Text Capture's starting point by that amount. I'll do more experimentation when I have a chance.

_________________
Daniel Stelzer


Top
 Profile Send private message  
Reply with quote  
PostPosted: Mon Oct 31, 2016 11:24 pm 
Offline

Joined: Tue Mar 09, 2010 2:34 pm
Posts: 5115
Location: Burlington, VT
OK, while I was falling asleep a few nights ago an idea came to me about just doing this with I7 texts anyway, and then when I went to implement it I realized that I'd forgotten what my original desired behavior was. But I figured maybe I can do this with I7 texts anyhow--have one list of texts to be the capture stack, have one text to be the stuff that would ordinarily go in "[the captured text]" (that's popped text), and then have another text to be the stuff that I wanted to push back to the capture text buffer (that's cumulative buffer), and when I need to push or pop the captured text again I just add the cumulative buffer on to the front of it.

Here's what I have right now. I've only tested it in the one case but I have to go to bed, where perhaps I'll get another idea. As I say below I'm pretty unsure now whether the second half of the definition of "pop the text capture stack" makes any sense at all.

Code:
Lab is a room.

Include Text Capture by Eric Eve.

The text capture stack is a list of texts that varies. The popped text is a text that varies. The cumulative buffer is a text that varies.

To clear the text capture stack: truncate the text capture stack to 0 entries.

To push the text capture stack:
   if text capturing is active:
      stop capturing text;
      let T be the substituted form of "[cumulative buffer][captured text]"; [not sure if substituted form is necessary]
      add T at entry 1 in the text capture stack;
   start capturing text.
   
To pop the text capture stack:
   if text capturing is active:
      stop capturing text;
      now the popped text is the substituted form of "[cumulative buffer][captured text]";
      if the number of entries in the text capture stack is greater than 0:
         now the cumulative buffer is entry 1 of the text capture stack;
         remove entry 1 from the text capture stack;
         start capturing text;
   otherwise if the number of entries in the text capture stack is greater than 0: [I'm not sure any of this is needed, or works]
      now the popped text is entry 1 of the text capture stack;
      remove entry 1 from the text capture stack;
   otherwise:
      now the popped text is "".

To say start reversing:
   push the text capture stack.

To say finish reversing:
   pop the text capture stack;
   say "[popped text in reverse]".

To decide what text is (T - a text) in reverse:
   let output string be some text;
   let N be the number of characters in T;
   repeat with index running from 1 to N:
      now output string is "[character number index in T][output string]";
   decide on output string.

When play begins: say "[start reversing]Foo[start reversing]bar[finish reversing]baz[finish reversing]."


Top
 Profile Send private message  
Reply with quote  
PostPosted: Mon Oct 31, 2016 11:41 pm 
Offline
User avatar

Joined: Wed Oct 14, 2009 4:02 am
Posts: 2432
So the current text capture implementation uses memory streams, because it is simple, and because it allows it to work for the Z-Machine.

If you were happy to limit it to Glulx it may be possible to use the filter IO system instead of memory streams.

Start capturing would add a new text to the stack, and if it's the first entry on the stack, switch to the filter IO system.

The filter function would add the character to the end of the top text of the stack.

End capturing would return the topmost text on the stack, and turn off the filter IO system if the stack is empty.

This might be simpler to implement, but if anything used the @glk opcode to print directly, then it wouldn't be captured. Depending on what you need it for, that might be fine.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Mon Oct 31, 2016 11:54 pm 
Offline

Joined: Tue Mar 09, 2010 2:34 pm
Posts: 5115
Location: Burlington, VT
Dannii wrote:
This might be simpler to implement


Not for me!


Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next

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