• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
tom_mai78101

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

10 posts in this topic

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.

[b]EDIT[/b]: 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. Edited by tom_mai78101
0

Share this post


Link to post
Share on other sites
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.

[CODE]
<message>
<title>This is a title</title>
<npc>frank</npc>
<text>This is a message</text>
</message>
[/CODE]

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

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

Share this post


Link to post
Share on other sites
In what language?

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

Share this post


Link to post
Share on other sites
One of the easiest patterns to parse (in my opinion), is CSV: [url="http://en.wikipedia.org/wiki/Comma-separated_values"]Comma-seperated values[/url].

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:
[code]MSG_BOX, "title", "message"
MSG_BOX, "title 2", "message 2"
MyFunction, param1, param2, param3[/code]

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.
1

Share this post


Link to post
Share on other sites
[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.
[/quote]

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

Share this post


Link to post
Share on other sites
[quote name='tom_mai78101' timestamp='1346916352' post='4977106']
[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.
[/quote]

I thought it's independent of whatever language you are using. [img]http://public.gamedev.net//public/style_emoticons/default/dry.png[/img]
[/quote]

The [i]format [/i]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?
1

Share this post


Link to post
Share on other sites
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.
1

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
Google answers that in 20 seconds: [url="http://stackoverflow.com/a/454913/1177073"]http://stackoverflow.com/a/454913/1177073[/url]
0

Share this post


Link to post
Share on other sites
That result is for UNIX and Windows system. Which is totally wrong. :/

This is what I tried using just after I posted [i]that[/i] post up there: [source lang="java"]String.split(System.getProperty("line.separator"))[0];[/source]
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0