
In Lua, and binds stronger than or meaning that and expressions are evaluated first.
AEGISUB TEMPLATE LIKE THAI KARAOKE CODE
If the syllable duration is longer than 100 ms the first sub-expression is true, and the code block returns "f", otherwise the entire and expression is false, and the right-hand argument of the or expression is returned. To create simple conditionals within code blocks you can use the and and or operators to chain values and conditions. Operator precedence rules are those of regular arithmetic.Ī code block should always return a string or numeric value, if it returns a boolean, a table or something else it might cause a warning and the resulting line containing the wrong output. Most simple mathematical expressions work just like you'd expect them to. They are expanded before the code block is parsed, so to the Lua interpreter the inline variables look like regular constants. It is possible to use inline variables within code blocks. You create a code block by surrounding the code by exclamation marks, like this: (There is a way to do basic conditionals in code blocks though, see below.)

This means you (among other things) can't do assignments or use if statements within code blocks, you must use a code line if you want to do any of those things. Code blocks are used to insert more complex things than can be expressed with inline variables.Ĭode blocks are required to be single Lua expressions, since a return statement is automatically prepended to the code. This may or may not change in later versions of Karaoke Templater.Ī code block is a block of Lua code within a template line.

This is a limitation of the execution model. You cannot have templates with char or multi modifiers run per-character/per-highlight interspersed with code lines. They are run interspersed with furi templates. They are run interspersed with syl templates.įuri Code lines in the furi class are run when a new furigana syllable is encountered. Syl Code lines in the syl class are run when a new syllable is encountered. They are run interspersed with line/ pre-line templates in the order they appear. Line Code lines in the line class are run when a new line is encountered.

This is the default class, if you don't specify a class for a code line it's automatically in the once class. This is usually the best place to define functions and general tables of values you need to look up later. Once Code lines in the once class are run exactly one time, before any templates are applied. You specify the class of the code line in the Effect field after the code keyword.

Some of them are the same, and some only exist for one or the other. Like there's multiple classes of template lines there's also multiple classes of code lines.
