Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 tom_mai78101   Members   -  Reputation: 577

Like
0Likes
Like

Posted 05 September 2012 - 02:02 AM

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.orgmtllib pyramid.mtlo Cubev 0.833333 -0.291667 -1.166666v 0.833333 -0.291667 0.833333v -1.166667 -0.291667 0.833333v -1.166666 -0.291667 -1.166667v -0.166667 1.458333 -0.166667v 0.833333 -0.291667 0.833334usemtl Materials offf 1 2 3 4f 6 1 5f 5 3 6f 3 5 4f 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.

Edited by tom_mai78101, 05 September 2012 - 04:04 AM.


Sponsor:

#2 nox_pp   Members   -  Reputation: 491

Like
2Likes
Like

Posted 05 September 2012 - 10:24 AM

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


#3 Telastyn   Crossbones+   -  Reputation: 3730

Like
0Likes
Like

Posted 05 September 2012 - 11:23 AM

In what language?

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

#4 Servant of the Lord   Crossbones+   -  Reputation: 21217

Like
1Likes
Like

Posted 05 September 2012 - 11:33 AM

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.
It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#5 tom_mai78101   Members   -  Reputation: 577

Like
0Likes
Like

Posted 06 September 2012 - 01:25 AM

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

#6 Telastyn   Crossbones+   -  Reputation: 3730

Like
1Likes
Like

Posted 06 September 2012 - 07:54 AM


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. Posted Image


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?

#7 Radikalizm   Crossbones+   -  Reputation: 2993

Like
1Likes
Like

Posted 06 September 2012 - 08:10 AM

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!


#8 CC Ricers   Members   -  Reputation: 835

Like
0Likes
Like

Posted 06 September 2012 - 08:50 AM

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.
My development blog: Electronic Meteor

#9 tom_mai78101   Members   -  Reputation: 577

Like
0Likes
Like

Posted 08 September 2012 - 09:12 PM

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.

#10 Servant of the Lord   Crossbones+   -  Reputation: 21217

Like
0Likes
Like

Posted 08 September 2012 - 09:43 PM

Google answers that in 20 seconds: http://stackoverflow.com/a/454913/1177073
It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#11 tom_mai78101   Members   -  Reputation: 577

Like
0Likes
Like

Posted 10 September 2012 - 03:57 AM

That result is for UNIX and Windows system. Which is totally wrong. :/

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS