Scripting Dialogue? How do I approach this?

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

Faith
01-12-2005, 07:40 AM
Hi!
I made this example for you which includes the script "engine" I made just now using this IniReader thingie. I coded it in a while, so it might contain some errors.

I'll tell you all the things you can do by scripting:

[Beginning]
Print=Hi. I'm some guy.#Here is the story of my life. Blah blah blah blah blah.##Would you like some money?
Choices=Yes#No?
Choice1=Money
Choice2=NoMoney

[Money]
Print=Here's some money#Do whatever you want with it.
Call=End

[NoMoney]
Print=Fine, be that way.#I'll just leave then, *******!
Call=ChangeSourceFile
NewSource=AppPath\Storyline2.txt#Beginning

Now, Everything is divided in to sections above, There's the section Beginning, which is called always when the Dialogue class is made for the first time.

- Print=Blaablaablaa#Blaablaablaa
It always prints your text to the screen
The # sign means a linebreak
If You like to put choices, you put:
- Choices=Yes#No?
And the # sign separates the different choices
You should have a corresponding
Choice1, Choice2 for each instance of choice you have in the Choices,
understand?
I.E.
Choice1=Money
Choice2=NoMoney
The Idea here is
Choice#=NextSectionName
The parser changes the section to the corresponding choice
like if you choose Yes, then you'll Go to Money and do that sections stuff,and if No then it goes to NoMoney

- Call=Something
The call has at the moment two options which you can use:
1. Call=End
This will display the ending message
2. Call=ChangeSourceFile
This call will make the parser check the new dialogue source file
I.E. I have in the NoMoney section:
Call=ChangeSourceFile
NewSource=AppPath\Storyline2.txt#Beginning
If a call "ChangeSourceFile" is made, the NewSource=Something is checked
ChangeSourceFile and NewSource must be used together
You can use: Call=ChangeSourceFile#End, if you want :p
Now what you can use with the changeSourceFile are:
AppPath\Filename.Txt#StartingSectionName
or
Filepath#StartingSectionName
Examples:
NewSource=AppPath\Storyline2.txt#Beginning
NewSource=C:\Documents and Settings\**\My Documents\Visual Studio Projects\Test2\bin\Storyline2.txt#Beginning
Now that's about what the parser can do,
You can use this parser as an example, or use the class in any way you wish or modify it, whatever, you could add all kinds of cool effects :)

Faith
01-12-2005, 08:08 AM
Dude dude, You have to do a dialogue creator just for the sake of coolness :p
Like, which comes with DLG.NET Framework and supports managed features :D
Nah, really a IDE for the scripting language would be so cool and easy to do :)
and equally useful as a map editor for a tile-based game (Not all that useful :D)
(OrganizedPosting.Com, I tell you, that's a Emoticon 4-Combo!)

ThePentiumGuy
01-12-2005, 02:25 PM
Wow thanks a lot dude :). Heh. That's a nice ... emoticon thing lol.
I'll give your thing a try :D. I'm wondering what ReadINI is though. I'll have a look at the code and get right back to you.

Thanks a lot. I'll use this as a guide to help me program my own editor thing.

-The Pentium Guy

ThePentiumGuy
01-12-2005, 04:21 PM
Hey. Thanks a lot. I spent a few hours working with your code and I understand all of it EXCEPT one part:

Function ReadINI(ByRef Section As String, ByRef KeyName As String, ByRef FileName As String) As String
Dim debug As Integer
Dim sRet As String
sRet = New String(Chr(0), 500)
debug = getprivateprofilestring(Section, KeyName, "0", sRet, Len(sRet), FileName)
sRet = Left(sRet, debug)

ReadINI = sRet

End Function

Why do you need the Left command? It works fine without it. Oh also, if you try to use the Left command inside.. let's say Form1_load, it's a differnet Left (t thinks you're tlaking about form1's Left property), so can you please give me the namespace where Left is found? Thanks.

You have a tiny bug there though, and I figured out hwo to fix it.

[NoMoney]
Print=Fine, be that way.#I'll just leave then, *******!
Call=ChangeSourceFile
NewSource=AppPath\Storyline1.txt#Beginning

Change that last line (change Storyline2 to Storyline1), and run the program. Press 2. And then press 2 again, it won't work.

To fix it:
If System.IO.File.Exists(FilePath) = False Then
MsgBox("Source change failed, the destination file was not found")
Err()
Exit Sub
Else
ParseSection()
Exit Sub '<-- Add this line
End If

The reason is, once ParseSection() is called after the Else, it finishes the sub. Once it finished the sub it resumes from there. It's kind of hard to explain, it took me about an hour of experimentation with breakpoints and wahtnot.

Thank you so much.
-The Pentium Guy

Faith
01-12-2005, 04:45 PM
Yes, I just programmed in a whim, so I'm glad to have helped, also an interesting thing to do, I'm glad you understood all of it, and that you were able to fix such a bug, you'll have to add loads of cool features to it... ;) I think the Left command is used just to get the right amount of characters out of the text file,
It could be replaced with:

sRet = sRet.Substring(0, debug)

Left() is legacy I think, and that is the .NET equivalent, also, may I add that that IO class is as old as time itself, from the ages before vb6, and I got it from some o' my friends :)

I get the problem you described, I made the program afterall ;)

It's always very motivating to help people who are willing to help themselves...

Cheers :)

ThePentiumGuy
01-12-2005, 07:06 PM
Once again, thanks. I'm gonna add a ****load of features ;). Like literally AddMoney to the inventory...etc. Nice and innovative to use an ini parser to read a text file lol :D.

-The Pentium Guy

Faith
01-13-2005, 04:12 AM
If you can, show it to me when you got the ****load of features piled up ;)

ThePentiumGuy
01-13-2005, 05:34 AM
Sure (These forum filters really suck you know?).

Right now I'm working on writing the text to the screen like a typewriter (So that instead of printing everything at once to the screen, it gets printed character by character until it reaches the end), and I'm doing this in GDI+.

The AddMoney basically works with the clsInventory class and adds the specified amount (Call=AddMoney#30 or something).

I'll probably add some calls like:
LearnSpell#Nameofspell <-- all you need is the name because the attributes of that specific spell will be stored somewhere else in the game (Some othejr text file I guess)
DropItem#Nameofitem#Index <-- You might have more than 1 item, so I just put index. 0 would mean you'd drop the first instance of that item. Something like that.

You know what I mean ;). Oh and I'm doign this RPG for a tutorial series I'm writing on my site, and I'll give you credit for helping out on the INI parser :D.

-The Pentium Guy

Faith
01-13-2005, 08:00 AM
Sounds extremely sweet :)
It'd probably have to be LearnSpell=Nameofspell1#NameofSpell2 ;)
The to-screen-like-typewriting might be a cool idea...
Darn, I've always wanted to do some RPG, and got the motivation, but I ain't got no ideas, I envy you :)

- The AMD Guy

ThePentiumGuy
01-13-2005, 02:06 PM
- The AMD Guy
Dam you lol XD.
Yeah AMD pwns intel though :(. But I'll stand by intel's side like a faithful servant unless they go way down.

The only motivation I have for writing this RPG is to write these tutorials (www.vbprogramming.8k.com/tutorials/main.htm).

-The Pentium Guy

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum