LVNAuth Tutorials - Reusable Scripts

Reusable Scripts

Reusable scripts are an important part of LVNAuth. They let you create scripts that you can call multiple times throughout your visual novel. This will be essential when creating long visual novels.

Differences between a Reusable script and Scene script

Here are 3 differences between reusable scripts and scene scripts:

  1. Dialogue text cannot be used in reusable scripts. If you try to put dialogue text in a reusable script, the dialogue text will simply be ignored, but no error will occur.

  2. The command to run a reusable script is: <call: a name here>, whereas the command to run a scene is: <scene: chapter name, scene name>.

  3. Reusable scripts can accept values. For example: <call: move character, name=rave>. We passed in rave as the name.

Uses for Reusable scripts

Load commands

Let's say you have 5 chapters in your visual novel and all 5 chapters use the same sprites. That means you would need to add the same <load...> commands to all 5 chapter scripts for each of the sprites you want to use, such as: <load_character> or <load_object>, etc.

What you could do instead is create one reusable script with all the <load...> commands that all 5 chapters need, and then use the <call> command to run the reusable script from each of the 5 chapters.

All 5 chapters would need to run the same reusable script, but if you need to make a change for when loading sprites, it can all be done in one reusable script rather than 5 separate scripts.

Animation

Reusable scripts are great for running repetitive commands which can be especially useful for animation. For example: blinking lights or a sprite that goes back and forth or in a specific pattern. The way to do this is to have multiple reusable scripts that call each other one after another.

For example, create two reusable scripts. Name one of them 'light on' and the other 'light off'.

Reusable script name Purpose
light on Show a sprite
light off Hide a sprite

in the light on script, you could have:

<object_show: green light>
<after: 60, light off>


Then in the light off script, you could have:

<object_hide: green light>
<after: 60, light on>

This is all assuming you have a sprite named green light.
What the two reusable scripts will do is call each other every 60 frames. Every 60 frames is 1 second, so to make it blink every 2 seconds, change it to 120 for both scripts.

The same kind of technique can be used for repetitive movement animations, where one reusable script calls another.

Movement animation depends more on where the location of a sprite is rather than fixed amount of time. So for movement, it can be better to use a command such as <object_after_movement_stop: reusable script name> which will run a reusable script that you specify, after the sprite has stopped moving.

We saw some examples on how reusable scripts are useful for repetitive animations.

Passing values to reusable scripts

You can pass different values to reusable scripts. This can let you use the same reusable script for different sprites.

Let's say you have a reusable script named move car with the following 3 lines in it:

<object_show: car>
<object_move: car, 2, right, 0, up>
<object_start_moving: car>

It's a reusable script that moves a car sprite towards the right by 2 pixels each frame. But what if we want to do the same thing with a truck sprite? We could create another reusable script, specifically for moving a truck sprite, but imagine if we had 10 or 20 sprites that we want to move in a similar fashion. It would become tedious having so many reusable scripts that do almost the same thing.

So now we can re-write our reusable script to take in values. First, let's rename our reusable script from move car to move vehicle because it won't be just for cars anymore.

Then, we'll change our script to this:

<object_show: (@vehicle)>
<object_move: (@vehicle), 2, right, 0, up>
<object_start_moving: (@vehicle)>

Then when we call our new reusable script, we can pass it a value to it like this:

<call: move vehicle, vehicle=car>

and if we want to move a truck sprite, we can use the same reusable script by passing a different value to it:

<call: move vehicle, vehicle=truck>

Explanation

First, in our reusable script, we replaced any instances of car to vehicle and we added an @ symbol in front of it and surrounded it with parenthesis, like this: (@vehicle) The @ symbol surrounded with parenthesis tells LVNAuth that the reusable script will accept values from the caller of the reusable script.

When we use the <call> command, we pass in vehicle=car (we use the word vehicle here because that's how we defined the placeholder in the reusable script. If we had a different placeholder in the reusable script, we would use that name instead). Finally, when we pass in a value using the <call> command, we don't need to use special symbols like the @ symbol surrounded by parenthesis, so it's just: vehicle=car or vehicle=truck.

Last updated: Sat 27 April 2024