LVNAuth Tutorials - Variables and Conditions

Jump to section:

Variables:

Introduction to variables
Creating a variable
Updating a variable
Using and showing a variable's value
Pass a variable's value to a reusable script

Conditions:

Conditions
OR logic
AND logic
Between
Not Between
Else

Variables

Before we get into conditions, we need to understand how to use variables and why they're used in LVNAuth.

Simply put, variables hold values. The value of a variable can be text or numeric, or a combination of both. The purpose of variables is to keep track of decisions made by the viewer of your visual novel.

Variables consist of 2 things: a name and a value. In other words, each variable has a name and each variable has a value.

For example, a character in your visual novel might need to make a decision that will impact the reaction of other characters in the visual novel. So you could ask the viewer to make that decision on behalf of the character. The decision gets put into a variable and you could decide what dialogue text to show based on the variable's value.

Creating variables

You can create a variable in 2 different ways.

1) Create a variable using the editor in LVNAuth by clicking the Variables button.

img

2) Create a variable using the command: <variable_set>

To create a variable the first way (by clicking the Variables button), click 'New Variable' at the top and give the variable a name. After the variable shows up in the list, double-click the cell in the Values column and type in a value. You could also leave the value blank if you plan on populating the value later in your visual novel.

To create a variable the second way using the command: <variable_set>, you could write a command like this:

<variable_set: fav_flower, red rose>

So in the command above, we've created a variable named fav_flower (favourite flower) and we've given it a value of red rose.

Variable names cannot contain spaces, periods, or commas.

Updating a variable's value

To update a variable's value, simply use the command. That command is used for both creating variables and updating existing variables.

Here is an example that will update the variable fav_flower to yellow rose:

<variable_set: fav_flower, yellow rose>

Using and showing a variable's value

You could use the value of a variable in 3 different ways:

1) Show a variable's value in a character's dialogue
2) Pass a variable's value to a reusable script
3) Create a condition based on a variable's value

Show a variable's value in a character's dialogue

<variable_set: fav_flower, red rose>

# Character dialogue text
Oh so your favourite flower is ($fav_flower).
That's my favourite too!

So we surround a variable's name with parenthesis and put a dollar $ sign in front of the variable to have it show the variable's value. ($like_this)

Pass a variable's value to a reusable script

Let's say we have a reusable script named greeting that takes in any name and greets it.

Hello (@name)

The parenthesis () and @ sign mean that the reusable script will accept a value from the caller of the script.

So in our main script (not the reusable script), we could call that reusable script and pass in a variable's value.

<set_variable: char_name, Theo>

<call: greeting, name=($char_name)>

So when the visual novel is played, it would show: hello Theo

The third way brings us into the topic of conditions.

Conditions

Starting with LVNAuth version 0.6, condition commands can be used which allow you to run specific lines in a script depending on a variable's value.

Here's a simple script which will have the character show different dialogue depending on the value of the variable: fav_flower (favourite flower).

<variable_set: fav_flower, red rose>

<case: ($fav_flower), is, red rose, flower check>
Red roses are my favourite flower too!
I think my local flower shop has some!
<case_end>

<case_else>
You don't like red roses?
That's ok!
<case_end>

The script above will cause the character to show different sentences depending on the value of the variable: fav_flower

This line requires a little bit of explaining:

<case: ($fav_flower), is, red rose, flower check>

($fav_flower) gets the variable's value, which is red rose.

The keyword, is, gets used to see if the variable's value is red rose. The comparison check is case-sensitive.

The last part, flower check, is a name that we give to the case command.

The name doesn't get shown to the viewer of the visual novel. The purpose of the name, flower check, is if we use the <or_case> command, the <or_case> command needs to know which <case> command to compare with, and that's where the name gets used.

We could have given it any name, such as ABC. The important part is that the name makes sense to you. This field is optional if you don't plan on using <or_case> later on in comparison with your <case> command.

However, if you use <or_case> later in your script, you'll need to specify a name in your <case> command so that your <or_case> command knows which <case> command to compare with.

OR logic

Let's say we want to show a specific dialogue text if a variable's value is red rose OR yellow rose.

It would look like this:

<variable_set: fav_flower, red rose>

<case: ($fav_flower), is, red rose, flower check>
<or_case: ($fav_flower), is, yellow rose, flower check> 

Roses are my favourite flower too!
I think my local flower shop has some!

<halt>

<case_end>

AND logic

Let's say we want to show a specific dialogue text if a variable's value is red AND the a different variable's value is yellow.

<variable_set: fav_fruit, strawberry>
<variable_set: fav_vegetable, carrot>

<case: ($fav_fruit), is, strawberry, fruit check>
<case: ($fav_vegetable), is, carrot, veggy check> 

I like strawberries and carrots too!

<halt>

<case_end>

The AND logic doesn't actually use the word 'and'. You can use multiple <case> commands one after the other to make it an 'and' logic.

Notice how the case names (fruit check and veggy check) are different and it still works. That's because case names are only needed when using <or_case>. However a name is still required even when not using <or_case>. This might change in a future update to make names optional, but for now it's required.

BETWEEN

We can use the BETWEEN operator to look for a numeric range.

Here is an example that checks if the variable: price is between 5 and 10.

<variable_set: price, 7>

<case: ($price), between, 5 and 10>

($price) is between ($from) and ($to)

<case_else>
($price) is not between ($from) and ($to)

<case_end>

<halt>

In the example above, it will show: 7 is between 5 and 10

NOT BETWEEN

Here is another example, but this time using NOT BETWEEN.

<variable_set: price, 100>

<case: ($price), not between, 5 and 10>

($price) is not between ($from) and ($to)

<case_else>
($price) is between ($from) and ($to)

<case_end>

<halt>

In the example above, it will show: 100 is not between 5 and 10

Else

We can use the command as a fall back if a command does not become satisfied.

<variable_set: fav_flower, tulip>

<case: ($fav_flower), is, red rose, flower check>
<or_case: ($fav_flower), is, yellow rose, flower check> 

Roses are my favourite flower too!
I think my local flower shop has some!

<case_else>

You don't like roses?
That's ok!

<case_end>

<halt>

In the example script above, the lines 'You don't like roses? That's ok!' will be shown. Notice how <case_end> is used only one-time near the end.

Last updated: Mon 28 October 2024