Two Posts(Re: Word Capture) 09/15/2006 04:10 AM CDT
Pasting two posts over from the GS4 boards.

I'll put them in seperate posts to keep the length minimal.

I don't recall anyone posting about this...and it's sort of useful info even if it's widely known. :P

-Chris



Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
Reply
Re: Two Posts(Re: Word Capture) 09/15/2006 04:10 AM CDT
So the recent spell-up script thread demonstrates that you can match more than one thing in a given paragraph, as long as the only commands inbetween are front-end only commands. This leads to some interesting applications.

For a while, I've thought that the two biggest problems with SF are it's inability to do much with strings, and its inability to catch text from the game to be saved to variables. Well, scratch off the latter.

This is a basic script that demonstrates a technique to save game output to variables. The following script will repeat anything anyone else says (please only use it in private). I've also made a .get script using this technique which will try to get and stow anything in the "You also see" line. It's really quite powerful.



debug off
reset:
setvariable word
matchre abc /(says|exclaims|asks), /i
matchwait
abc:
matchre quote /^\"/i
matchre a /^a/i
matchre b /^b/i
matchre c /^c/i
matchre d /^d/i
matchre e /^e/i
matchre f /^f/i
matchre g /^g/i
matchre h /^h/i
matchre i /^i/i
matchre j /^j/i
matchre k /^k/i
matchre l /^l/i
matchre m /^m/i
matchre n /^n/i
matchre o /^o/i
matchre p /^p/i
matchre q /^q/i
matchre r /^r/i
matchre s /^s/i
matchre t /^t/i
matchre u /^u/i
matchre v /^v/i
matchre w /^w/i
matchre x /^x/i
matchre y /^y/i
matchre z /^z/i
matchre space / /i
matchre done /.$/
matchwait

quote:
goto abc
a:
setvariable word %word%a
goto abc
b:
setvariable word %word%b
goto abc
c:
setvariable word %word%c
goto abc
d:
setvariable word %word%d
goto abc
e:
setvariable word %word%e
goto abc
f:
setvariable word %word%f
goto abc
g:
setvariable word %word%g
goto abc
h:
setvariable word %word%h
goto abc
i:
setvariable word %word%i
goto abc
j:
setvariable word %word%j
goto abc
k:
setvariable word %word%k
goto abc
l:
setvariable word %word%l
goto abc
m:
setvariable word %word%m
goto abc
n:
setvariable word %word%n
goto abc
o:
setvariable word %word%o
goto abc
p:
setvariable word %word%p
goto abc
q:
setvariable word %word%q
goto abc
r:
setvariable word %word%r
goto abc
s:
setvariable word %word%s
goto abc
t:
setvariable word %word%t
goto abc
u:
setvariable word %word%u
goto abc
v:
setvariable word %word%v
goto abc
w:
setvariable word %word%w
goto abc
x:
setvariable word %word%x
goto abc
y:
setvariable word %word%y
goto abc
z:
setvariable word %word%z
goto abc
space:
setvariable word %word%
goto abc
done:
put '%word%
goto reset



Enjoy.

- Greminty
Reply
Re: Two Posts(Re: Word Capture) 09/15/2006 04:11 AM CDT
Heh... Wow. This is much prettier in TextPad.
I've actually wanted some sort of text collection for many years. I tried this method before and couldn't get it to work (I see now why).

I like to use utilities in my scripts... In this case, I will use this utility to easily capture text as so: Copy and paste the last portion of this post (after the string of pound signs) to facilitate it, and start the utility like so...

* At the BEGINNING OF THE SCRIPT, MAKE SURE TO setvariable LabelError_Checking to 0. The LabelError routine that I use is supposed to guarantee that this is always 0 unless the variable is being used at that moment, but I forget and if you use it you'll forget as well. Just... do it. Trust me.
* Set the variable ExtractWords_MaxWords. Use 0 for no maximum number of words collected or add a number to impose a limit
* Set the variable ExtractWords_InitialIgnore. This is a string that will precede the words you wish to collect. These words and any before them in that paragraph will not be collected. The utility does NOT add a carat (^) to the beginning of this string. The utility does add the necessary slashes
* Set the variable ExtractWords_StopWhen. This variable is a regular expression that defines when the utility should STOP capturing words. The utility DOES add a carat to the beginning of this string, so don't do so yourself. It also adds the necessary slashes.
* Set the variable ExtractWords_ReturnTo. This is the label to which the utility will return when it's done extracting.
* goto BeginExtractingWords. This will start examining the text using the guidelines you've input.

Note that this utility does not destroy the counter or the save.

Right now it'll only extract alpha words because that's all I've used it for so far. The ability to extract numbers, commas or punctuation should be fairly trivial.

To get information from the utility, examine the following variables:

ExtractWords_Word# to get the #th word extracted
ExtractWords_Word0 to get the full string
ExtractWords_Word0_ to get the full string, delimited by underscores. This may be useful for further GOTOs
ExtractWords_NumberOfWords to get the number of words matched
ExtractWords_StopReason to get the reason why extraction stopped (either numberwords or match, for reaching your max specified or reading your StopWhen).

I suggest that you squelch setvariable:, but that's just me...

On another, possibly related note... StormFront variables are not designed to hold 10MB of data. Just in case anyone was curious.

Example:
The following portions of the script are followed by the utility text at the end of the post.

debug off
setvariable LabelError_Checking 0
goto Begin
Begin:
setvariable ExtractWords_MaxWords 3
setvariable ExtractWords_InitialIgnore You
setvariable ExtractWords_StopWhen hands.$
setvariable ExtractWords_ReturnTo AnnounceGlance

match ValueIsDamaged appears to be noticeably damaged.
match ContinueExtractingAppraisalValue It appears to be in
put glance
goto BeginExtractingWords
AnnounceGlance:
echo %ExtractWords_Word0%
echo %ExtractWords_Word0_%
echo %ExtractWords_Word1%
echo %ExtractWords_Word2%
echo Number %ExtractWords_NumberOfWords%
echo StopReason %ExtractWords_StopReason%

Returns in this case:
glance down at
glance_down_at
glance
down
Number 3
StopReason numberwords

The utility follows. Copy it and paste it into the bottom of the script. Note that your LabelError will be in this area now, and the script needs the LabelError to be intact (although you can extend the LabelError functionality quite easily).

##########################################
BeginExtractingWords:
setvariable CurrentAction extracting
setvariable ExtractWords_PreviousCounter %c
setvariable ExtractWords_JustStarted 1
setvariable ExtractWords_PreviousSave %s
setvariable ExtractWords_Word1
counter set %ExtractWords_MaxWords%
counter add
setvariable ExtractWords_MaxWordsPlusOne %c
counter set 1
setvariable ExtractWords_StopWhenRegex ^%ExtractWords_StopWhen%
matchre ContinueExtractingWords /%ExtractWords_InitialIgnore%/i
ExtractWords_WordBoundary_Ignore1:
ContinueExtractingWords:
matchre ExtractWords_StopDueToMatch /%ExtractWords_StopWhenRegex%/
matchre ExtractWords_Lettera /^[a]/i
matchre ExtractWords_Letterb /^[b]/i
matchre ExtractWords_Letterc /^[c]/i
matchre ExtractWords_Letterd /^[d]/i
matchre ExtractWords_Lettere /^[e]/i
matchre ExtractWords_Letterf /^[f]/i
matchre ExtractWords_Letterg /^[g]/i
matchre ExtractWords_Letterh /^[h]/i
matchre ExtractWords_Letteri /^[i]/i
matchre ExtractWords_Letterj /^[j]/i
matchre ExtractWords_Letterk /^[k]/i
matchre ExtractWords_Letterl /^[l]/i
matchre ExtractWords_Letterm /^[m]/i
matchre ExtractWords_Lettern /^[n]/i
matchre ExtractWords_Lettero /^[o]/i
matchre ExtractWords_Letterp /^[p]/i
matchre ExtractWords_Letterq /^[q]/i
matchre ExtractWords_Letterr /^[r]/i
matchre ExtractWords_Letters /^[s]/i
matchre ExtractWords_Lettert /^[t]/i
matchre ExtractWords_Letteru /^[u]/i
matchre ExtractWords_Letterv /^[v]/i
matchre ExtractWords_Letterw /^[w]/i
matchre ExtractWords_Letterx /^[x]/i
matchre ExtractWords_Lettery /^[y]/i
matchre ExtractWords_Letterz /^[z]/i
matchre ExtractWords_WordBoundary /^[ ]/i
matchre ExtractWords_FinalCollection /.*$/
matchwait

ExtractWords_StopDueToMatch:
setvariable ExtractWords_StopReason match
goto ExtractWords_FinalCollection

ExtractWords_WordBoundary:
goto ExtractWords_WordBoundary_Ignore%ExtractWords_JustStarted%
ExtractWords_WordBoundary_Ignore0:
setvariable ExtractWords_JustDidWordBoundary 1
# 1 or 0 is not arbitrary for the previous variable
counter add
counter subtract %ExtractWords_MaxWordsPlusOne%
goto ExtractWords_CheckMaxWords_%c%

ExtractWords_HandleLabelError:
counter add %ExtractWords_MaxWordsPlusOne%
setvariable ExtractWords_Word%c%
goto ContinueExtractingWords

ExtractWords_CheckMaxWords_0:
setvariable ExtractWords_StopReason numberwords
goto ExtractWords_FinalCollection

ExtractWords_FinalCollection:
setvariable CurrentAction wordbuilding
goto ExtractWords_FinalCollection_%ExtractWords_StopReason%

ExtractWords_FinalCollection_numberwords:
counter add %ExtractWords_MaxWordsPlusOne%
counter subtract
goto ExtractWords_FinalCollection_CountWords

ExtractWords_FinalCollection_match:
counter subtract %ExtractWords_JustDidWordBoundary%
goto ExtractWords_FinalCollection_CountWords

ExtractWords_FinalCollection_CountWords:
setvariable ExtractWords_NumberOfWords %c
counter set 1
goto ExtractWords_FinalCollection_Build0first

ExtractWords_FinalCollection_Build0first:
setvariable ExtractWords_Word0 %ExtractWords_Word1%
save %ExtractWords_Word1%
goto ExtractWords_FinalCollection_Build0

ExtractWords_FinalCollection_Build0:
counter add
setvariable ExtractWords_Temp %%ExtractWords_Word%c%%%
setvariable ExtractWords_Word0 %ExtractWords_Word0% %ExtractWords_Temp%
save %s%_%ExtractWords_Temp%
counter subtract %ExtractWords_NumberOfWords%
goto ExtractWords_FinalCollection_ContinueBuild%c

ExtractWords_FinalCollection_ContinueBuild0:
counter set %ExtractWords_PreviousCounter%
setvariable ExtractWords_Word0_ %s
save %ExtractWords_PreviousSave%
goto %ExtractWords_ReturnTo%

ExtractWords_FinalCollection_HandleLabelError:
counter add %ExtractWords_NumberOfWords%
goto ExtractWords_FinalCollection_Build0

ExtractWords_Lettera:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%a
goto ContinueExtractingWords
ExtractWords_Letterb:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%b
goto ContinueExtractingWords
ExtractWords_Letterc:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%c
goto ContinueExtractingWords
ExtractWords_Letterd:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%d
goto ContinueExtractingWords
ExtractWords_Lettere:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%e
goto ContinueExtractingWords
ExtractWords_Letterf:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%f
goto ContinueExtractingWords
ExtractWords_Letterg:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%g
goto ContinueExtractingWords
ExtractWords_Letterh:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%h
goto ContinueExtractingWords
ExtractWords_Letteri:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%i
goto ContinueExtractingWords
ExtractWords_Letterj:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%j
goto ContinueExtractingWords
ExtractWords_Letterk:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%k
goto ContinueExtractingWords
ExtractWords_Letterl:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%l
goto ContinueExtractingWords
ExtractWords_Letterm:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%m
goto ContinueExtractingWords
ExtractWords_Lettern:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%n
goto ContinueExtractingWords
ExtractWords_Lettero:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%o
goto ContinueExtractingWords
ExtractWords_Letterp:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%p
goto ContinueExtractingWords
ExtractWords_Letterq:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%q
goto ContinueExtractingWords
ExtractWords_Letterr:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%r
goto ContinueExtractingWords
ExtractWords_Letters:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%s
goto ContinueExtractingWords
ExtractWords_Lettert:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%t
goto ContinueExtractingWords
ExtractWords_Letteru:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%u
goto ContinueExtractingWords
ExtractWords_Letterv:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%v
goto ContinueExtractingWords
ExtractWords_Letterw:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%w
goto ContinueExtractingWords
ExtractWords_Letterx:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%x
goto ContinueExtractingWords
ExtractWords_Lettery:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%y
goto ContinueExtractingWords
ExtractWords_Letterz:
setvariable ExtractWords_JustStarted 0
setvariable ExtractWords_JustDidWordBoundary 0
setvariable ExtractWords_CurrentWord %%ExtractWords_Word%c%%%
setvariable ExtractWords_CurrentWordValue %ExtractWords_CurrentWord%
setvariable ExtractWords_Word%c% %ExtractWords_CurrentWordValue%z
goto ContinueExtractingWords

LabelError:
goto LabelError_Error_%LabelError_Checking%

LabelError_Error_1:
echo You've an infinite loop in your LabelError!
setvariable LabelError_Checking 0
exit
LabelError_Error_0:
setvariable LabelError_Checking 1
goto LabelErrorBranch_%CurrentAction%

LabelErrorBranch_extracting:
setvariable LabelError_Checking 0
goto ExtractWords_HandleLabelError
LabelErrorBranch_wordbuilding:
setvariable LabelError_Checking 0
goto ExtractWords_FinalCollection_HandleLabelError
Reply
Re: Two Posts(Re: Word Capture) 09/15/2006 02:30 PM CDT
Regular expressions are your friend.

I don't know that I see the exact reason for the utility as is...and from what I can tell blocks of text from DR are actually lines (no CR LF) so they are single line matches unless interrupted before all the data is displayed in the window (usually it's all received just delay in display).

I don't know what set of regexp rules/guidelines stormfront follows or if it has its own but it's possible to do something similar with less work by using meta-characters. I'd suggest people look into that, what rules/guidelines/idiosyncrasies exist if they plan on using regexp within any application.

I don't think it allows multi-line matches yet or perhaps some other issues but it has been a while since I messed around in Stormfront.

Good to see that people are still doing new or interesting things and posting about it.

I am --- Navak
Reply