What is the easiest text pattern for a text file, in use of a text parser for monologues and dialog pop-ups?

Started by
9 comments, last by tom_mai78101 11 years, 7 months ago
I'm looking into a text pattern that I could use for a basic format. This format will then be parsed by my program, and can easily be split into groups of strings for different purposes.

Recently, I have found out about the Wavefront OBJ format, which uses a pretty simple text pattern. Below is a given example.

[source lang="plain"]# Blender v2.63 (sub 0) OBJ File: ''
# www.blender.org
mtllib pyramid.mtl
o Cube
v 0.833333 -0.291667 -1.166666
v 0.833333 -0.291667 0.833333
v -1.166667 -0.291667 0.833333
v -1.166666 -0.291667 -1.166667
v -0.166667 1.458333 -0.166667
v 0.833333 -0.291667 0.833334
usemtl Material
s off
f 1 2 3 4
f 6 1 5
f 5 3 6
f 3 5 4
f 5 1 4
[/source]

I have decided to work my text pattern based around the OBJ format, shown above, so it kind of looked like this:

[source lang="plain"]#1 title:"This is a title." msg:"This is a message."
#2 title:"This is something else." msg:"This is fun to read."
#3 title:"This is wrong." msg:"This is nice."
#4 title:"t" msg:"m"[/source]

I was wondering if anyone else have insights on this. As far as I know, text parsing is one thing, but creating a custom pattern is another. Thanks in advance.

EDIT: I realized I made a mistake in choosing the text pattern I posted above. The downside of this text pattern, is that you can't concatenate String tokens broken up by one or more newlines. If some monologues / dialogues have extended text messages, the only way to make it work is to turn off Text Wrapping in some text editors. Are there other ways I could do this, by adding in newlines and stuff?

I did use the String.split() method, but as far as I know, it doesn't seem to work on newlines. Unless there's a better way to fix this, I'm not quite sure.
Advertisement
I would use an already established format, like XML. Then you won't have to write a parser, and you get lots of other goodies for free.


<message>
<title>This is a title</title>
<npc>frank</npc>
<text>This is a message</text>
</message>


You can structure your data however you'd like really:


<conversation title="foo_meets_bar">
<message from="foo">
Argh ye scurvy scallawags.
</message>
<message from="bar">
Pleasure to make your acquaintance.
</message>
</conversation>

Between Scylla and Charybdis: First Look <-- The game I'm working on

Object-Oriented Programming Sucks <-- The kind of thing I say

In what language?

C# for example has a number of auto-serialization libraries that make it silly to write your own format.
One of the easiest patterns to parse (in my opinion), is CSV: Comma-seperated values.

You read an entire line, then separate the line along the commas.
Each line could be it's own message box. Or, the first parameter of each line could indicate what the line is.

Example:
MSG_BOX, "title", "message"
MSG_BOX, "title 2", "message 2"
MyFunction, param1, param2, param3


You only need to find: A) each comma. B) each newline.
The only complication is if you hit a quotation, to keep going forward ignoring every comma or newline until you find the closing quotation. Also ignore quotations prefixed with \ so you can escape it if you like. \"
Optionally, you could parse \n as newlines also.

In what language?

C# for example has a number of auto-serialization libraries that make it silly to write your own format.


I thought it's independent of whatever language you are using. <_<

[quote name='Telastyn' timestamp='1346865796' post='4976896']
In what language?

C# for example has a number of auto-serialization libraries that make it silly to write your own format.


I thought it's independent of whatever language you are using. dry.png
[/quote]

The format should be. That said, I'm guessing that the format will only ever be used by your app. At that point, why not save yourself a bunch of development time by applying an existing solution to a well known problem?
Another vote for XML here. There are tons of good writers and parsers available in many languages, it's easy to properly structure your data and it's perfectly humanly readable. With XML you could even write your own DTD for your file formats and use a validating parser if you really want to.

I gets all your texture budgets!

For message boxes and dialog boxes I think XML is a bit overkill. With only two different variables (title and message) it's very easy to keep track over what represents what, without needing any element names to designate what the value is for. I would choose a CSV format.

I would also make a suggestion for JSON for more complex data.

New game in progress: Project SeedWorld

My development blog: Electronic Meteor

Only if when the time comes for our development plan to work more on dialogues for things other than dialogs, we could try some of those.

The only problem that comes to mind, is how to make String.split() work with newlines in Java. If I can get around that, then everything should be cleared to go.
Google answers that in 20 seconds: http://stackoverflow.com/a/454913/1177073

This topic is closed to new replies.

Advertisement