🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Extracting and integrating text from/to file for proofreading

Started by
5 comments, last by SyncViews 5 years, 3 months ago

I wanted to add some easy option for players to help me proofread the text in game.

I have a simple script in LUA, like this:


if npc==1 then
	picture("wizard.png");
	title("Thargiul","Master of LUA");
	print("Hello!");
end

So, basically there is some code plus 2 functions that contain text print() and title(). The first have always 1 and the second always 2 parameters, so it's totally trivial at that front. In some very rare cases it can have \" inside a string (but that's a problem I can ignore, so handling these is a bonus).

Now, I wanted to extract the text from it and make, I don't know, maybe CSV file? So it would look like this "Thargiul","Master of LUA","Hello!". Then someone would take the file, correct it and send it back to me. Then I would integrate it back with the main file containing both text and code.

 

The question is, how to approach this? Both extracting the file and then reintegrating?

Technically I know the answer how I could do it so it's more like a question how to handle this the best way (I would not want to spend too much time coding this). Also I could consider options like using some tool (only if not overly complex) to do it instead of coding the solution.

I'm not interested in the gettext style solution (file parsed and then made into a database and then the game reads from the database, I want a solution where the corrected text is integrated back with the script).

 

 

 

 

 

Stellar Monarch (4X, turn based, released): GDN forum topic - Twitter - Facebook - YouTube

Advertisement

You probably should create an expandable list

By all means i mean win32 application with a control in it.

So you add items only when you find if npc = and you add this number

Then for the expandable thing: imagine you have a treeview control: so whenwver you add subitems like picture tile print there is a plus icon near main item.

This would be the best approach for you

You should probably have the other way round, keep all your dialogs in a file or a tool, maintain the dialogs there and then import them into your code so you don't have a roundtrip

Look in to internationalization (i18n).  Not only would it let you keep your text in an external file for proofreading, but also let you keep your translations in a text file for localization (l10n).

Stephen M. Webb
Professional Free Software Developer

11 hours ago, Shaarigan said:

You should probably have the other way round, keep all your dialogs in a file or a tool, maintain the dialogs there and then import them into your code so you don't have a roundtrip

That would not make any sense scripting wise. The script is basically all text with occassional simple if statements. So, separating text from script (which is 95% text) would make the script... well, quite empty :) It would not make any practical sense and it would be a horror to edit.

Stellar Monarch (4X, turn based, released): GDN forum topic - Twitter - Facebook - YouTube

 

On 4/2/2019 at 8:36 PM, Acharis said:

I'm not interested in the gettext style solution (file parsed and then made into a database and then the game reads from the database, I want a solution where the corrected text is integrated back with the script).

Most tools that do this are intended for localisation. I quiet like the gettext solution, rather than like "story.main_quest.1.intro.1" or some such with the text defined entirely externally and often opqaue hard to follow "id's" (especially when placeholders, plurals, etc. get involved), but like you said, it won't update the source if you want to correct the native text that way.

If you wanted to do it yourself, Id stick with the gettext '_("mystring")' style, as at least that is something you should be able to regex without needing a complete lua parser (and without picking up things like "wizard.png" which are not display text). Assuming you kept track of the original string -> updated string mapping, it should be fairly easy to regex replace them back into the source.

 

To cover all eventualities, especially complex cases like splitting strings across multiple source lines however, you probably do want a full parser. It should be fairly possible then to pull out the strings (either from an AST or token stream) and potentially might be possible to reconstruct the file to your satisfaction (a simple conversion back to source will likely "reformat" any newlines, indentations, etc.). There are of course already parsers around, and I suspect at least one gives you the data in a suitable format.

 

On 4/2/2019 at 8:36 PM, Acharis said:

I wanted to add some easy option for players to help me proofread the text in game.

Another thing to consider for the purpose of proof reading, especially if you have complex dialogue involving multiple characters, is that keeping the context is difficult and can have a big impact on if a given piece of text is correct or not. Probably the easiest way is to just give people the lua file itself if you have such text, as any tooling is likely to end up being complex.

This topic is closed to new replies.

Advertisement