ThePentiumGuy
01-11-2005, 05:27 PM
I'm trying to write a Dialogue class, although I have no idea how to approach this. I drew a little dialogue "box" in which text will be drawn. That box can only hold 5 lines of text.
As of now, I know how to (But I haven't done) something like this:
dialogue.txt:
Hi. I'm some guy.
Here is the story of my life. Blah blah blah blah blah.
Where in that case,
"Hi. I'm some guy" would appear in one dialogue box, and when you push space:
"Here is the story of my life. Blah blah blah blah blah." would appear in another dialogue box. Since it is in one line, the program will automatically split the text into 2,3,4,or 5 different lines (as needed).
However, I'm getting EXTREMLELY confused when it comes to choices in the box. Will this work?
Hi. I'm some guy.
Here is the story of my life. Blah blah blah blah blah.
Choice:2,Yes,No:Would you like some money?
#Choice
Yes:
2
Here's some money
Do whatever you want with it.
No:
2
Fine, be that way.
Go away.
#EndChoice
Go Home
This works like so:
"Hi I'm some guy"
"Here is the story of my life. Blah blah blah blah blah."
"Would you like some money" <Choose Yes>
"Here's some money"
"Do Whatever you want with it"
"Go Home"
OR
"Hi I'm some guy"
"Here is the story of my life. Blah blah blah blah blah."
"Would you like some money" <Choose No>
"Fine, be that way."
"Go away."
"Go Home"
That itself is confusing. The 2 after "Choice:" represents that there are 2 choices.The 2 after Yes or No represent how many lines of text there are after that.
I have no idea how to read something like this (above) and parse it. I could first try:
line = reader.readline
If Not line.contains(":") Then
'Read it like normal
'This is easy
Else
s =line.split(":")
if s(0) = "Choice" then LookAtChoice(line) End If
End If
Public Sub LookAtChoice(line as string)
Dim colonSplit() as string
Dim commaSplit() as String
Dim numberofchoices as integer
colonsplit = line.Split(":") 'Split "Choice:Yes,No:Would you like some money?"
texttodisplay = colonsplit(2) ' "Would you like some money"
commasplit = colonsplit(1).Split(",")
numberofchoices = commasplit(0)
' I'll create a DisplayChoiceList function somewhere else.
' The game will only be able to hold 2, 3, or 4 choices
if numberofchoices = 2 then DisplayChoiceList(numchoices, commasplit(1), commasplit(2))
if numberofchoices = 3 then DisplayChoiceList(numchoices, commasplit(1), commasplit(2), commasplit(3))
if numberofchoices = 4 then DisplayChoiceList(numchoices, commasplit(1), commasplit(2), commasplit(3), commasplit(4))
UpdateTextToDisplay()
End Sub
'Later, when the player chooses a choice:
Public sub CheckForChoices(myChoice as String)
Reader.readline() 'The #Choice line is just for cleansiness
Dim numLines as string
loop until reader.readline = myChoice & ":" 'The line looks like " Yes: "
numlines = cint(reader.readline) ' the 2 in the line after Yes: .. or No:
for x as integer = 1 to numlines
texttodisplay = reader.read
UpdateTextToDisplay()
next
Loop until reader.readline = "#EndChoice"
'Skip the rest of the choices
Wend
Wend
End Sub
WOW. By the way that's pseudocode (I typed it in inside the forum, so excuse any syntax errors).
Do you guys think that this will work?
-The Pentium Guy
As of now, I know how to (But I haven't done) something like this:
dialogue.txt:
Hi. I'm some guy.
Here is the story of my life. Blah blah blah blah blah.
Where in that case,
"Hi. I'm some guy" would appear in one dialogue box, and when you push space:
"Here is the story of my life. Blah blah blah blah blah." would appear in another dialogue box. Since it is in one line, the program will automatically split the text into 2,3,4,or 5 different lines (as needed).
However, I'm getting EXTREMLELY confused when it comes to choices in the box. Will this work?
Hi. I'm some guy.
Here is the story of my life. Blah blah blah blah blah.
Choice:2,Yes,No:Would you like some money?
#Choice
Yes:
2
Here's some money
Do whatever you want with it.
No:
2
Fine, be that way.
Go away.
#EndChoice
Go Home
This works like so:
"Hi I'm some guy"
"Here is the story of my life. Blah blah blah blah blah."
"Would you like some money" <Choose Yes>
"Here's some money"
"Do Whatever you want with it"
"Go Home"
OR
"Hi I'm some guy"
"Here is the story of my life. Blah blah blah blah blah."
"Would you like some money" <Choose No>
"Fine, be that way."
"Go away."
"Go Home"
That itself is confusing. The 2 after "Choice:" represents that there are 2 choices.The 2 after Yes or No represent how many lines of text there are after that.
I have no idea how to read something like this (above) and parse it. I could first try:
line = reader.readline
If Not line.contains(":") Then
'Read it like normal
'This is easy
Else
s =line.split(":")
if s(0) = "Choice" then LookAtChoice(line) End If
End If
Public Sub LookAtChoice(line as string)
Dim colonSplit() as string
Dim commaSplit() as String
Dim numberofchoices as integer
colonsplit = line.Split(":") 'Split "Choice:Yes,No:Would you like some money?"
texttodisplay = colonsplit(2) ' "Would you like some money"
commasplit = colonsplit(1).Split(",")
numberofchoices = commasplit(0)
' I'll create a DisplayChoiceList function somewhere else.
' The game will only be able to hold 2, 3, or 4 choices
if numberofchoices = 2 then DisplayChoiceList(numchoices, commasplit(1), commasplit(2))
if numberofchoices = 3 then DisplayChoiceList(numchoices, commasplit(1), commasplit(2), commasplit(3))
if numberofchoices = 4 then DisplayChoiceList(numchoices, commasplit(1), commasplit(2), commasplit(3), commasplit(4))
UpdateTextToDisplay()
End Sub
'Later, when the player chooses a choice:
Public sub CheckForChoices(myChoice as String)
Reader.readline() 'The #Choice line is just for cleansiness
Dim numLines as string
loop until reader.readline = myChoice & ":" 'The line looks like " Yes: "
numlines = cint(reader.readline) ' the 2 in the line after Yes: .. or No:
for x as integer = 1 to numlines
texttodisplay = reader.read
UpdateTextToDisplay()
next
Loop until reader.readline = "#EndChoice"
'Skip the rest of the choices
Wend
Wend
End Sub
WOW. By the way that's pseudocode (I typed it in inside the forum, so excuse any syntax errors).
Do you guys think that this will work?
-The Pentium Guy