Ok, I really wanted to help:
if file exist("TestFile.txt") > 0 then delete file "TestFile.txt"
`Create a sample text file:
open to write 1, "TestFile.txt"
write string 1, "[Q1] How are you feeling today?[2][/Q1]"
write string 1, "Good, thank you.[Q2]"
write string 1, "Not good, leave me alone [A1]"
write string 1, "[Q2] Great! Are you a programmer? I am one...[2][/Q2]"
write string 1, "Yes. [A2]"
write string 1, "No. [A3]"
write string 1, "[A1] Ohw, okay... [Terminate][/A1]"
write string 1, "[A2] Great! I'll definatley will contact you again. [Terminate][/A2]"
write string 1, "[A3] Ohw, okay. Maybe I'll see you again some time... [Terminate][/A3]"
close file 1
print "Starting Dialogue. Press any key."
wait key
`Start Dialogue
Tag$ = "[Q1]"
EndTag$ = "[/Q1]"
Dialogue:
Question$ = GoTag(Tag$, 1, "TestFile.txt")
Question$ = GetOpenTagContent(Question$, Tag$, EndTag$)
`Print the questions to the screen
print FilterTags(Question$, "[", "]")
`Get answers
Answers$ = GetTagContent(Question$, "[", "]")
if lower$(Answers$) = "terminate"
goto Terminate
else
Answers = val(Answers$)
endif
`Store answers
dim Ans$(Answers)
for a = 1 to Answers
read string 1, Ans$(a)
`display and get answer
print str$(a) + ": " + FilterTags(Ans$(a), "[", "]")
next a
`Get answer
repeat
input "Answer: ", Ans
until Ans > 0 and Ans <= Answers
`Process
Tag$ = "[" + GetTagContent(Ans$(Ans), "[", "]") + "]"
EndTag$ = "[/" + GetTagContent(Ans$(Ans), "[", "]") + "]"
gosub Dialogue
Terminate:
print "dialogue ended"
wait key
delete file "TestFile.txt"
end
`*****************************
`Functions
`*****************************
function GoTag(Tag$, f, filename$)
if file open(f) > 0 then close file f
open to read f, filename$
repeat
read string f, GetTag$
if left$(GetTag$, len(Tag$)) = Tag$ then exitfunction GetTag$
until file end(f) > 0
close file f
endfunction ""
function GetTagContent(St$, BeforeSgn$, AfterSgn$)
Ret$ = ""
Content = 0
for i = 0 to len(St$)
if mid$(St$, i) = AfterSgn$ then Content = 0
if Content = 1 then Ret$ = Ret$ + mid$(St$, i)
if mid$(St$, i) = BeforeSgn$ then Content = 1
next i
endfunction ret$
function GetOpenTagContent(St$, StartTag$, EndTag$)
Ret$ = ""
Content = 0
if len(St$) > len(StartTag$) + len(EndTag$)
for i = 0 to len(St$) - len(EndTag$)
Searched$ = right$(St$, len(St$) - i)
if left$(Searched$, len(EndTag$)) = EndTag$ then Content = 0
if Content = 1 then Ret$ = Ret$ + mid$(St$, i)
if left$(Searched$, len(StartTag$)) = StartTag$ then Content = 1 : i = i + len(StartTag$)
next i
endif
endfunction Ret$
function FilterTags(St$, BeforeSgn$, AfterSgn$)
Ret$ = ""
Content = 1
for i = 0 to len(St$)
if mid$(St$, i) = BeforeSgn$ then Content = 0
if Content = 1 then Ret$ = Ret$ + mid$(St$, i)
if mid$(St$, i) = AfterSgn$ then Content = 1
next i
endfunction Ret$
function Trim(St$)
Ret$ = ""
for i = 0 to len(St$)
if mid$(St$, i) <> " " then Ret$ = Ret$ + mid$(St$, i)
next i
endfunction Ret$
This is a serie of Tag functions I created. You can use it to create your very own syntax.
Mine was for example:
[Q#] [/Q#] is a question. Between these tags, the question is written + a closed tag with the number of answers available.
for example, the fifth question:
[Q5]Action? [5][/Q5]
The answers, have no special tags. But are ended with a closed tag too, to check which action should be used. [Terminate] for ending the dialoge, you can add your own commands by using cases. A default case means it has to search again in the file for the current tag.
[Q5]Action? [5][/Q5]
Attack [Att]
Defense [Def]
Magic [Mag]
Run [Run]
Suicide [Suc]
Dialogues aren't the only thing you can do with it. For example, loading maps. You have a [Matrix] section, an [Object] section, a [Portal] section, etc.
Multifunctional

...