|
Talahaski Enchanter
Joined: 10 Oct 2000 Posts: 656 Location: USA
|
Posted: Mon May 19, 2008 12:05 am
story Teller |
Can somebody help me figure out how to do this.
I have some stories and poems stored in individual text files.
I would like to create a alias that I can type in the name of the story and it will open the file and my character will say the story one line at a time with a short pause between each line. I also need some way to abort the reading or pause the reading.
The biggest problems is how to pause or abort
This is what I'm thinking thus far, but does not do everything I need
open the file using the parm + .txt
read the file into a variable
replace line breaks with | to turn it into a stringlist
foreach string say the text
or
open the file using the parm + .txt
call to a function that
reads the next line
If Not end of file
Say the text
delay a few seconds
call itself |
|
_________________ Talahaski
dartmud.com 2525 |
|
|
|
Caled Sorcerer
Joined: 21 Oct 2000 Posts: 821 Location: Australia
|
Posted: Mon May 19, 2008 12:35 am |
Store information on the number of lines in the story, in the first line of the text file.
Extract that information to a variable at the beginning (could even have information in it that sets the pause between each line if you wanted.
Name: <storyname> Lines: 23 Special Pauses: 17: 5000, 22: 1000
(where 17 and 22 are non-default pauses in milliseconds. Just an idea though.)
Use #File 1 storyname.txt
to set the story
Use #READ 1 1
to get the info from the first line, including totalStoryLines=23
currentStoryLine=2
#AL readstory {
#IF (%1="pause") {storypaused=1}
#IF (%1="continue" {storypaused=0}
#IF (!$storyPaused) {#READ 1 @currentStoryLine
#ADD currentStoryLine 1
#IF (@currentStoryLine!>@totalStoryLines) {#AL +2 {readstory}}}}
"readstory"
to read the story line by line.
"readstory pause"
to stop it
"readstory continue" to restart it
I didn't elaborate on the customised pause lengths because I have no idea if you're actually interested in that. |
|
_________________ Athlon 64 3200+
Win XP Pro x64 |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon May 19, 2008 12:36 am |
Either way works, but each time the function is called or the foreach tries a new item, check to see if some variable is 1. If it is, abort.
For the pausing, you might find the easiest way is to put it in its own thread an use #waitsignal. Another method would be to use a copy of the source variable for your forall:
$file=@file
#forall $file {}
and then remove the lines from @file when you say them. When you "pause" the reading, you really abort it and then just resume it from the @file variable. |
|
|
|
Talahaski Enchanter
Joined: 10 Oct 2000 Posts: 656 Location: USA
|
Posted: Tue May 20, 2008 12:04 am |
Thanks for the reply. I have something working now, except for one minor problem.
After reviewing your responses, here is what I did.
I decided to use a menu button instead. So I setup a button called StoryTelling type=menu with the following selections
Start
Code: |
#CLASS StoryTelling 1
StoryTelling/StoryControl=1
$StoryName=%prompt( "", "What story do you want to tell?")
#file 1 %concat($StoryName,".txt")
TellStory |
Pause
Code: |
StoryTelling/StoryControl=2 |
Stop
Code: |
StoryTelling/StoryControl=3 |
Continue
Code: |
StoryTelling/StoryControl=1 |
Then created the following alias
Code: |
#CASE @StoryTelling/StoryControl {say %read(1,0)
#alarm +5 {TellStory}} {#sh Story Telling is paused
#alarm +10 {TellStory}} {#CLOSE 1
#CLASS StoryTelling 0} |
Everything is working very well except when it gets to the end of the file. When it just issues say command to the mud without any text. Is there any way to check before the %read if I've reached the end of the file? |
|
_________________ Talahaski
dartmud.com 2525 |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Tue May 20, 2008 12:30 am |
I would suggest checking to see if %read returned a null. Then put a space in all the blank lines in your stories so that %read will return " " instead of "" for a blank line and only return the null when it gets to the end.
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Talahaski Enchanter
Joined: 10 Oct 2000 Posts: 656 Location: USA
|
Posted: Tue May 20, 2008 1:17 am |
Thanks, got it working good now.
Here is the completed code.
Alias TellStory
Code: |
#SWITCH (@StoryTelling/StoryControl)
(1) {$line=%read(1,0)
#IF ($line) {say $line
#alarm +5 {TellStory}} {#SH Completed Telling this Story
StoryTelling/StoryControl = 3
#CLOSE 1
#CLASS StoryTelling 0}}
(2) {#SH Story Telling is paused
#alarm +10 {TellStory}}
(3) {#SH Completed Telling this Story
#CLOSE 1
#CLASS StoryTelling 0} |
|
|
_________________ Talahaski
dartmud.com 2525 |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue May 20, 2008 3:18 am |
If you want pausing to be a bit more responsive, I suggest you do away with the alarm loop that periodically checks, and just run the tellstory alias again manually when you set the variable back to 1. I assume you have an alias that sets the storycontrol value, so it should be trivial to run the alias at the same time.
|
|
|
|
|
|