LiminaliaLiminalia
Technical docs: Writing scenarios: Conditions, choices, variables

Conditions, choices, variables

Open in Claude (new tab)
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 @if is 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 expression to @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.x is bad-guard; the suggested fix is if=(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, write if= on the choice line.
  • The name of a @let with if=(…) can be used in later lines too (if the condition is false, it stays without a value).
  • lim backport writes it back as cond="…" (commands that become two or more tags are wrapped in [if exp="…"] to [endif]).

Jump targets

How to write itWhere it goes
#labelA label in the same file
fileThe start of that file
file#labelA 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 @set puts 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 writeLook
image= (hover= too)Image button
No image=, but width= and height=Invisible click area
NeitherText 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 itMeaning
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=trueCalls 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 @if to 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 warning no-choice-shown is 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 true false is either true or false; other variables are taken to be one of the compared values, unset, or something else

Time limit

  • Write @choice timeout=10s default=2 on the @choice line. A bar shows the remaining time, and when time runs out, the default choice (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 default is 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 (push and so on) return a new array without changing the original.
  • Strings are only "…". Assignment is done only with @set and @let (both take = += -= *= /=; @let i += 1 is 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 with game.d.a or game.d["a"]. They can be written inside {= …} too, as in {= {"a": 1}["a"]} in text.
OperationRule
==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 callA wrong number of arguments is a syntax check error (bad-arguments)

Progress and the environment being played in (functions answered by the runtime):

FunctionValue
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 visits and read are 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-label unknown-file), and that the choice in chosen exists somewhere (warning unknown-option). The text in chosen is 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() is pc, and app() and replaying() are false.
  • TyranoScript’s expressions don’t have these, so lim backport reports expressions containing them as things it can’t write back.

Random numbers:

  • random() is 0 or more and less than 1, and random(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 coverage runs with one fixed seed by default (--seeds N runs N times with different seeds).

Variables

How to write itLifetime
game.xKept in the save
system.xShared by all saves
temp.xOnly during the current session
@let x = …Local variable. Only within that file or @define
save.versionRead only. The version of the game that made the save data (“Save versions” below)
  • Initial values go in variables in 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__, constructor and prototype can’t be used in variable names, members or keys (game.x, game["x"], @let names, @define parameter names) (syntax check error forbidden-property). At run time too, an assignment that goes through them is an error and isn’t made, and reading them gives null.
  • Misspellings are reported. When a game. or system. variable is read but never given a value anywhere (not by @set, a command’s result, an initial value in variables, 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’s variables; see docs/plugins.md).
  • Setting check.variables in liminalia.json to "declared" allows only the variables written in variables. Every place that reads or writes a game. or system. variable that isn’t written there gets a warning (undeclared-variable).
  • Variables with no initial value. A variable with no value yet is null. += -= *= /= calculate null as 0 (an empty string when adding text with +=), but comparisons (< <= > >=) and arithmetic (+ - and so on) don’t treat it as 0 (null >= 2 is a runtime error). A place that reads a variable with no initial value in variables that 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 in variables ("game.trust": 0). temp. can’t go in variables, so give it a value first with @set temp.x = 0. For a @let local variable, @let x += 1 is the same as @let x = x + 1 and doesn’t treat null as 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 @for name) also gets a warning (uninitialized-variable; the fix is @let x = 0 on the line before).
  • When the expression of a condition (@if @elif @while @for, a line’s if=(expression), a choice’s if= locked= call=, if in 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 are string number int bool duration color variable (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.

    TypeValueWhat it checks
    asset(folder)An asset path (for asset(bgimage), from the background folder)That the asset exists (missing-asset, asset-case-mismatch)
    castA characterThat it’s in cast.json
    appearance variant positionA sprite set, variant, positionThat the character given as the same macro’s cast value has it
    targetA jump target (#label, file, file#label)That the label and file exist
    enum(a|b|c)One of fixed valuesThat it’s one of the values written
  • // lines directly above @define are 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 type target).

  • 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 @if and @jump can’t be macro names (error).

  • A - in a parameter name is written _ in expressions inside (first-name is {= first_name}, because - in an expression is subtraction).

  • Macros don’t change the caller’s variables. A @let inside 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 @end while the condition is true. The condition is judged the same way as @if. @elif @else can’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 expression to @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’s bad-for).
  • The expression is evaluated only once, before starting (rewriting game.items inside doesn’t change what’s looped over). The name is a local variable (as with @let, it can also be read after @end and keeps the last value; if the loop never runs, it has no value).
  • @elif @else can’t be written. Labels can’t be placed inside (label-in-if). Loops can be nested. game system temp save can’t be used as the name (bad-for).
  • TyranoScript has no equivalent, so lim backport reports 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, …) = expression on 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 as bad-function; if the body is a single @return, the suggested fix is the one-line form).
  • Inside, it can read its arguments and game system temp save. The @let local 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 @use that 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 (random and so on) (duplicate-function). A wrong number of arguments is bad-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 @if condition or {= …} in text. Use @function to 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 @end passes the lines in between to the macro as content. The content runs where @content is in the macro (it can be written any number of times).
  • The content runs with the caller’s local variables (@let). Labels, @content and @return can’t be written in the content.
  • Calling a macro without @content with @with is a warning (with-without-content; the content doesn’t run). Calling a macro with @content without @with makes @content do nothing.
  • Only @define macros can be called with @with (writing a command gives bad-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.x system.x temp.x).
  • @return (expression) can only be written inside @define (bad-return). @return without a value works as before.
  • TyranoScript has no return values, so lim backport reports macros that use a return value as things it can’t write back, as with @while and @with (as with adding a @define).

Using macros from another file (@use)

  • Write @use file at the outermost level of the file (@use common). Only the @define macros of the files you @use can be called.
  • At run time, that file is loaded first (they can still be called after loading a save). Only the @define macros are loaded; the file’s text doesn’t run.
  • Even if files @use each other (even in a loop), each is loaded only once.
  • If you call one without @use, the syntax check shows which file to @use.