Solarus-Games English Forum

Solarus => Development => Topic started by: MetalZelda on April 05, 2016, 12:20:15 AM

Title: [Solved] Ignoring a chunk of text ?
Post by: MetalZelda on April 05, 2016, 12:20:15 AM
Hi.

So earlier I was imaginating a mail system and how it should work. It works properly (https://github.com/MetalES/Project-Zelda/issues/4), but I am in need of help.

The mail's text content is stored in another file (see bellow), this is to ensure that translators will not be lost and also to keep string.dat clean (Only mail names are part of string.dat)

Everything works fine, except that I need to ignore a chunk of line in order to display the right page.

This is how a mail file looks like (of course, this is a test)
$ = Tell the engine to go to another line
Title: Re: Ignoring a chunk of text ?
Post by: Diarandor on April 05, 2016, 01:57:47 AM
Hi! I think this can be done using some of the Lua functions for strings. Probably the best option will be just using "string.match" (the function "string.find" could be useful too, but maybe worse). (I think "string.gmatch" is similar, but it gives an iterator to find patterns instead, if I am not wrong.) It should not be too hard (but I agree these things are annoying and too easy to forget). Fortunately there are good tutorials explaining how to get the patterns. Check the following links in the given order:

A very nice tutorial which I used once and found it greatly useful:
http://lua-users.org/wiki/PatternsTutorial

A manual about patterns which may help too:
http://www.lua.org/manual/5.2/manual.html#6.4.1

A list of Lua string functions (you do not need this now, but it may help for other purposes):
http://lua-users.org/wiki/StringLibraryTutorial

I cannot help you more since I have forgotten how to use the patterns, so I would need to study the tutorials again.

EDIT: you may also find some examples of uses of the "string.match" function in your dialog box script.

EDIT2: be careful because some of the characters you use (like "[" and "]") have special uses for the pattern syntax (they are called magic characters in the second link), as you can read in the tutorials. You can match them using "%" before them, i.e., with "%[" and "%]".
Title: Re: Ignoring a chunk of text ?
Post by: MetalZelda on April 05, 2016, 02:49:14 AM
Thanks Diarandor for the help, indeed, it is useful, but I might have find a easier way to do it using require instead of sol.load (and it just use the "$" formatting instead of a huge and long process of string manipulation

something like this also work, this is almost the same thing, but instead it use a Lua table to get the text, and it is still understandable for translators (plus, coms can be added to gave them hints since the format is lua)

This is how the mail file now looks like
Code (lua) Select
local text = {
-- [0] represent the page
[0] = (
"Header$" ..
"Line1$" ..
"Line2$" ..
"Line3$" ..
"Line4$" ..
"Line5$" ..
"Line6$" ..
"Line7$" ..
"Line8$"),
["reward"] = "heart_piece",
}

return text


It does work in game, I'm quite surprised

(http://i.imgur.com/ux4hngY.png)