Jump to content
• Advertisement

# Algorithm Extracting and integrating text from/to file for proofreading

## Recommended Posts

Posted (edited)

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

Edited by Acharis

#### Share this post

##### Share on other sites
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

#### Share this post

##### Share on other sites

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

#### Share this post

##### Share on other sites

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

#### Share this post

##### Share on other sites
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.

#### Share this post

##### Share on other sites
Posted (edited)

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.

Edited by SyncViews

## 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

• Advertisement
• Advertisement

• ### Popular Now

• 10
• 10
• 12
• 9
• 33
• Advertisement
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!