Conditions, choices, variables
On this page
@if game.trust >= 2
Yui "Then this will be quick."
@elif game.trust == 1
Yui "...I'll think about it."
@else
Yui "...I see."
@end
@choice
- Take the north road -> #north_road
- Take the south road -> #south_road
@end
@set game.trust += 1
@let count = game.trust * 2
@jump chapter2#start
@call common#interlude
@return
Blocks
- A block is always closed with
@end. Indentation is only for looks. - Put labels outside
@if. A label inside@ifis an error (label-in-if), because jumping into it would start in the middle of a branch without checking the condition. At run time too, a jump to that label is an error, and the jump isn’t made.
One-line conditions (if=(expression))
@bg room_night.jpg if=(game.night)
@chara Yuika smile if=(game.trust >= 2) time=300ms
@set game.met = true if=(!game.met)
@jump #bad_end if=(game.trust < 0)
@return if=(temp.done)
if=(expression)can be written on any command line, including@jump@call@set@let@return@content. If it’s false, the line is skipped (cond=in TyranoScript,if:in Naninovel).- It behaves the same as wrapping the line in
@if expressionto@end, and the syntax check and the flowchart see it the same way (the line after@jump … if=(…)is reachable, and the arrow on the map gets the condition). - It can also be written in the middle of the arguments (
@bgm night.ogg if=(game.night) volume=60). The value is always in(…)(if=game.xisbad-guard; the suggested fix isif=(game.x)). - It can’t be written on words that open blocks (
@if@elif@else@while@for@with@choice@define@function@script@use@end) or in{@…}in text (bad-guard). To show choices conditionally, writeif=on the choice line. - The name of a
@letwithif=(…)can be used in later lines too (if the condition is false, it stays without a value). lim backportwrites it back ascond="…"(commands that become two or more tags are wrapped in[if exp="…"]to[endif]).
Jump targets
| How to write it | Where it goes |
|---|---|
#label | A label in the same file |
file | The start of that file |
file#label | A label in that file |
(expression) | Decided at run time (@jump (game.next)). The value is a string in one of the three forms above |
A file is a path relative to the scenario folder, without the .lim extension. Scenarios in subfolders are separated with /
(for scenario/part1/chapter2.lim, @jump part1/chapter2#top). lim check, lim build and Studio treat scenarios in subfolders by the same names
(files and folders starting with . are ignored).
When the target is decided by an expression, the syntax check and the flowchart still read the candidate targets from the expression and confirm that each one exists.
- Strings in the expression (
(game.good ? "#a" : "#b")) - If the expression is only a variable, the strings that
@setputs in that variable and its initial value in liminalia.json - For a local variable from
@let, the expression of that@let
When they can’t be read (there is a @set that puts in something other than a string, the variable receives a command’s result, and so on), write the candidates with to=.
@jump (game.next) to=#north,#south
- Text -> (game.next) to=#a,#b
- If the candidates can’t be read and there is no
to=, it’s a warning (unknown-targets). - With
to=, a jump at run time to a target that isn’t among the candidates is an error instead of a jump.
Choices
@choice
- Check the door -> #door image=button/door.png hover=button/door_on.png x=120 y=300
- -> #window x=600 y=200 width=180 height=240
@end
@choice timeout=10s default=2
- Use the key -> #unlock if=(game.has_key)
- Turn back -> #back
@end
A choice line is - text -> target, and you can write its look and conditions after the target.
Look
| What you write | Look |
|---|---|
image= (hover= too) | Image button |
No image=, but width= and height= | Invisible click area |
| Neither | Text button |
x=y=set where it’s placed.- The text is used in records without a screen and for text-to-speech. It can be omitted only for image buttons and click areas (
- -> #window …).
Conditions and state
| How to write it | Meaning |
|---|---|
if=(expression) | Shown only when true. False choices aren’t shown, and the rest close up (same as [glink cond=…] in TyranoScript). The expression is always in (…), and true and false are judged the same way as @if |
locked=(expression) | If true, shown but can’t be pressed, instead of being hidden. Can be written together with if= |
call=true | Calls the target (@call), and after @return comes back to this choice and shows it again (for buttons that switch settings and so on) |
- You can’t wrap choices in
@ifto show them conditionally (only choice lines can go inside@choice). - If every
if=is false, no choices are shown, and the game stops in a state where clicking doesn’t advance (same as@stop). It’s the same as[s]after[glink]tags whose conditions are all false in TyranoScript, and a runtime warningno-choice-shownis given. - If every choice has
if=, none might be shown and the game might stop, so the syntax check warns (all-options-conditional). However, under the following conditions it tries every combination of variable values, and doesn’t warn if one choice is sure to be true (such as a last choice that’s shown only after all the others have been done).- The conditions only use variables as booleans as they are, or compare them with values using
==!=, joined with!&&|| - A variable compared only with
truefalseis either true or false; other variables are taken to be one of the compared values, unset, or something else
- The conditions only use variables as booleans as they are, or compare them with values using
Time limit
- Write
@choice timeout=10s default=2on the@choiceline. A bar shows the remaining time, and when time runs out, thedefaultchoice (counting from the top) is chosen. - While screens such as the menu, save, load, backlog or settings are open, the remaining time doesn’t go down (the bar stops too). When they close, it continues from where it was.
- If
defaultis omitted, or that choice isn’t shown or can’t be pressed, nothing is chosen and the game moves on past@end.
Expressions
A small expression language, not JavaScript.
- What you can use: arithmetic, comparison, logic, the ternary operator, arrays
[1, 2], dictionaries{"a": 1, b: 2}, indexing, registered functions (random numbers, numbers, strings and arrays, the real date and time; the list is under “Expression functions” in commands.md), and functions made with@function(below) - Functions that change arrays (
pushand so on) return a new array without changing the original. - Strings are only
"…". Assignment is done only with@setand@let(both take=+=-=*=/=;@let i += 1is the same as@let i = i + 1). - Dictionary keys are
"strings"or names. Writing the same key twice is a syntax check error. Read them withgame.d.aorgame.d["a"]. They can be written inside{= …}too, as in{= {"a": 1}["a"]}in text.
| Operation | Rule |
|---|---|
== | Compares types too |
+ | Adds if both are numbers. If either is a string, joins them ("Chapter " + game.n; numbers and booleans become text). Any other combination is an error |
/ | Dividing by 0 is an error (it doesn’t silently become null) |
| Function call | A wrong number of arguments is a syntax check error (bad-arguments) |
Progress and the environment being played in (functions answered by the runtime):
| Function | Value |
|---|---|
visits("#label") | How many times that label has been entered in this playthrough (kept in the save). It’s counted when the label line is passed, so read inside that label, it includes the current visit. It’s 1 on the first visit |
read("#label") | Whether that label has ever been entered in any playthrough (read status; shared by all saves) |
chosen("choice text") | Whether the choice with that text has been chosen in this playthrough (kept in the save) |
lang() | The language being played (ja, en and so on) |
platform() | pc or mobile (phones, tablets) |
app() | Whether it’s being played in an app (desktop or mobile version). false in a browser |
replaying() | Whether a replay from the extras is playing |
# check_arms
@if visits("#check_arms") == 1
Both arms are gone, cut off halfway down the upper arm.
@else
No arms.
@end
@jump #menu
- Targets in
visitsandreadare written the same way as for@jump(#label,file,file#label). A file alone gives how many times the start of the file was entered. Entering a label counts whether it’s reached by a jump (@jump@call, choices) or by continuing from the line above. - The syntax check confirms that labels and files in targets written as strings exist (
unknown-labelunknown-file), and that the choice inchosenexists somewhere (warningunknown-option). The text inchosenis the choice text with ruby replaced by its base text (the original, not a translation). - When running without a screen (
lim trace, the all-routes test),lang()is the language of the original,platform()ispc, andapp()andreplaying()arefalse. - TyranoScript’s expressions don’t have these, so
lim backportreports expressions containing them as things it can’t write back.
Random numbers:
random()is 0 or more and less than 1, andrandom(n)is an integer from 0 up to but not including n.- Random numbers are made from a seed (
seed), and the seed advances each time a random number is made. The seed is kept in the save, so loading gives the same results. lim coverageruns with one fixed seed by default (--seeds Nruns N times with different seeds).
Variables
| How to write it | Lifetime |
|---|---|
game.x | Kept in the save |
system.x | Shared by all saves |
temp.x | Only during the current session |
@let x = … | Local variable. Only within that file or @define |
save.version | Read only. The version of the game that made the save data (“Save versions” below) |
- Initial values go in
variablesin liminalia.json ({ "game.trust": 0, "system.cleared": false }).game.starts with this value every time the player chooses “New Game.” Variables missing from a loaded save are also filled in with this value.system.gets this value when it doesn’t have a value yet.temp.can’t be written here.
__proto__,constructorandprototypecan’t be used in variable names, members or keys (game.x,game["x"],@letnames,@defineparameter names) (syntax check errorforbidden-property). At run time too, an assignment that goes through them is an error and isn’t made, and reading them givesnull.- Misspellings are reported. When a
game.orsystem.variable is read but never given a value anywhere (not by@set, a command’s result, an initial value invariables, a plugin’s declaration, a flag in the project’s data, a record of unlocks the engine sets, or anything else), and a variable that is given a value has a similar spelling, it’s a warning (unset-variable; the suggested fix replaces it with that name:@if game.socre→game.score). If there’s nothing similar, it isn’t reported (so that variables a plugin sets silently aren’t reported by mistake. Variables a plugin sets go in the plugin’svariables; see docs/plugins.md). - Setting
check.variablesin liminalia.json to"declared"allows only the variables written invariables. Every place that reads or writes agame.orsystem.variable that isn’t written there gets a warning (undeclared-variable). - Variables with no initial value. A variable with no value yet is
null.+=-=*=/=calculatenullas 0 (an empty string when adding text with+=), but comparisons (<<=>>=) and arithmetic (+-and so on) don’t treat it as 0 (null >= 2is a runtime error). A place that reads a variable with no initial value invariablesthat is never given a value with=and only calculated with+=and the like gets a warning (uninitialized-variable; on a route that didn’t pick the option that adds to it, it’s compared with no value). To fix it, write an initial value invariables("game.trust": 0).temp.can’t go invariables, so give it a value first with@set temp.x = 0. For a@letlocal variable,@let x += 1is the same as@let x = x + 1and doesn’t treatnullas 0. A line that calculates a local variable from its previous value without a@let x = …on an earlier line (and that isn’t a parameter or the@forname) also gets a warning (uninitialized-variable; the fix is@let x = 0on the line before). - When the expression of a condition (
@if@elif@while@for, a line’sif=(expression), a choice’sif=locked=call=,ifin the data of standard commands) gives an error, a runtime error (runtime) is reported and the condition is treated as false (the branch for a true condition isn’t entered).
"check": { "variables": "declared" }
Macros (@define)
// Scene change macro (the one in the earlier template; the current template uses @scene-change and commandDefaults)
@define scene(image: asset(bgimage), time: duration = 800ms)
@window hide
@chara-hide-all time=(time)
@mask time=(time)
@bg (image)
@mask-off time=(time)
@window show time=300ms
@end
@scene image=room_night.jpg
-
@define name(parameter: type = default, …)to@end. The types arestringnumberintbooldurationcolorvariable(a variable that receives the return value; see below). -
You can also write types that are checked the same way as for built-in commands. The syntax check looks at the caller’s values just as it looks at a command’s arguments.
Type Value What it checks asset(folder)An asset path (for asset(bgimage), from the background folder)That the asset exists ( missing-asset,asset-case-mismatch)castA character That it’s in cast.json appearancevariantpositionA sprite set, variant, position That the character given as the same macro’s castvalue has ittargetA jump target ( #label,file,file#label)That the label and file exist enum(a|b|c)One of fixed values That it’s one of the values written -
//lines directly above@defineare shown in completion and descriptions as a summary of the macro. -
A call has the same form as a command (
@scene image=room_night.jpg). Inside, pass parameters to commands as(parameter name). -
An expression inside a macro that jumps to a parameter’s value, such as
@jump (to), is checked by the syntax check with the caller’s values (make the typetarget). -
A macro with the same name as a built-in command is used instead of the command (warning
define-shadows-command; the game doesn’t break when a newer version of the engine adds a command with the same name). Syntax words such as@ifand@jumpcan’t be macro names (error). -
A
-in a parameter name is written_in expressions inside (first-nameis{= first_name}, because-in an expression is subtraction). -
Macros don’t change the caller’s variables. A
@letinside with the same name as a parameter is an error (shadows-param).
Loops (@while)
@let i = 0
@while i < 3
Round {= i + 1}
@let i = i + 1
@end
- Repeats up to
@endwhile the condition is true. The condition is judged the same way as@if.@elif@elsecan’t be written. Labels can’t be placed inside (label-in-if). - The runtime stops when the number of lines it has run goes over a limit (default 1,000,000), so a loop that never ends stops there too. Text lines and each check of the loop condition count as one line each, not only command lines. The count isn’t reset for each loop; it’s the total of every line the runtime has run.
Looping over arrays (@for)
@for item in game.items
You have {= item}.
@end
@for name in keys(game.flags)
@set game.flags[name] = false
@end
@for name in expressionto@end. If the expression’s value is an array, its elements, and if it’s a dictionary, its keys, are put into the name one at a time, and the inside repeats (anything else is a runtime error; a literal number or string is the syntax check’sbad-for).- The expression is evaluated only once, before starting (rewriting
game.itemsinside doesn’t change what’s looped over). The name is a local variable (as with@let, it can also be read after@endand keeps the last value; if the loop never runs, it has no value). @elif@elsecan’t be written. Labels can’t be placed inside (label-in-if). Loops can be nested.gamesystemtempsavecan’t be used as the name (bad-for).- TyranoScript has no equivalent, so
lim backportreports it as something it can’t write back, as with@while.
Expression functions (@function)
@function rank(score) = score >= 80 ? "A" : score >= 50 ? "B" : "C"
@function heart(n) = n >= 3 ? "♥♥♥" : n == 2 ? "♥♥" : "♥"
Yui "Your grade is {= rank(game.score)}."
@if rank(game.score) == "A"
…
@end
@function name(argument, …) = expressionon one line makes a function that can be called in expressions. Its body is a single expression, and it only returns a value (it doesn’t change variables). Write it at the outermost level of the file (nested-function). It can’t be written in a block form from@function name(arguments)to@end(reported once asbad-function; if the body is a single@return, the suggested fix is the one-line form).- Inside, it can read its arguments and
gamesystemtempsave. The@letlocal variables of the place that calls it aren’t visible (so it behaves the same whenever it’s called). - It can be called in that file and in files that
@usethat file (as with macros). If you forget@use, the syntax check shows which file to@use. - A function can’t have the same name as a built-in function (
randomand so on) (duplicate-function). A wrong number of arguments isbad-arguments. - A function can call itself. If calls go deeper than 200 levels, it stops with a runtime error.
- The return value of a macro (
@define) (@return (expression)) can’t be used inside expressions. Macros show text and effects and may wait for them to finish, so they can’t run in the middle of an@ifcondition or{= …}in text. Use@functionto only calculate a value, and a macro for effects.
Passing content (@with and @content)
@define flashback(time: duration = 1s)
@tone sepia time=(time)
@content
@tone none time=(time)
@end
@with flashback time=600ms
Yui "...About that day."
@end
@with macro parameters…to@endpasses the lines in between to the macro as content. The content runs where@contentis in the macro (it can be written any number of times).- The content runs with the caller’s local variables (
@let). Labels,@contentand@returncan’t be written in the content. - Calling a macro without
@contentwith@withis a warning (with-without-content; the content doesn’t run). Calling a macro with@contentwithout@withmakes@contentdo nothing. - Only
@definemacros can be called with@with(writing a command givesbad-with).
Return values (@return (expression))
@define roll(sides: int = 6, into: variable)
@return (randint(1, sides))
@end
@roll sides=20 into=temp.r
- Give the macro one parameter of type
variable, and@return (expression)puts a value in that variable and ends the macro. The caller passes the variable to fill (game.xsystem.xtemp.x). @return (expression)can only be written inside@define(bad-return).@returnwithout a value works as before.- TyranoScript has no return values, so
lim backportreports macros that use a return value as things it can’t write back, as with@whileand@with(as with adding a@define).
Using macros from another file (@use)
- Write
@use fileat the outermost level of the file (@use common). Only the@definemacros of the files you@usecan be called. - At run time, that file is loaded first (they can still be called after loading a save). Only the
@definemacros are loaded; the file’s text doesn’t run. - Even if files
@useeach other (even in a loop), each is loaded only once. - If you call one without
@use, the syntax check shows which file to@use.