TyranoBuilder Visual Novel Studio Guide

Adding Basic Variables to your game using TyranoScript for TyranoBuilder Visual Novel Studio

Adding Basic Variables to your game using TyranoScript

Overview

This is a quick and dirty guide for adding basic variables to your game which can be called using TyranoScript script.This guide covers: * Creating Variables * Creating Random Number Variables * Displaying Your Variables * ELSE IF statementsThis guide requires no knowledge of Javascript (although it would help!)To get the most out of this guide, it is highly recommended that you complete the Official TyranoBuilder tutorial first, which is accessible through the HELP dropdown on the top menubar in TyranoBuilder.

Creating and Checking Numeric Variables

The purpose of this tutorial is to aid beginners (noncoders) in the process of creating a more dynamic game by creating variables in TyranoScript. The use of variables will allow you to create a much simpler timeline than you would have by relying on Labels, Branches, and Jumps alone. In this tutorial I will show you how to make a simple dialogue fork that is affected by a variable.

To get the most out of this tutorial, I suggest first completing the tutorial provided by the developer, which can be found by clicking “HELP > Tutorial” on the top menubar.

*note: be sure that you are placing your TyranoScript inside of TyranoScript tag boxes. While it is possible to inject TyranoScript inside of TEXT tag boxes, TyranoBuilder will automatically separate the script and the TEXT elements in to separate tag boxes in the timeline the next time you open your file. This can lead to some serious headaches. *

So, jumping right in….

The basic syntax for creating a custom variable is as follows:

1. [eval exp=”f.MyVar=0″]

*note: this tutorial will use line numbering. so do not include the number and dot at the beginning of each line in your scripts.*

Pictured: TyranoScript box on a Timeline that declares a variable.

The [eval] tag is used for evaluating expressions (exp). For more information on the tag itself, and other script tags, you can visit [link]

For now though, we are only interested in what is contained in the quotes.

f.MyVar is the variable being created. Feel free to change MyVar to the whatever name you wish, however you must include the “f.” before the name of the variable as it tells TyranoBuilder that this variable is a Game variable.

*TIP: You can also include “sf.” for assigning system variables.*

If you wish to display your variable, you would use the [emb] or “embed” tag. The syntax for using it to output our new variable would look this this:

1. [emb exp=f.MyVar]

It’s that simple. However, we will return to this tag later in the section on creating a Random variable. For now we’ll be moving on to [IF] [ELSE] tags in the next section.

IF ELSE statements: Using your variables to affect your game.

It can quickly become tedious creating LABELS and JUMPS for every single branch in the story of your game. This is where [if] and [else] tags become quite useful. So that is what I am about to show you how to use in this section of the tutorial. So let’s put our variables to good use in some IF ELSE statements.

First be sure that you have LABELS in your timeline to jump to. A simple “Yes” or “No” situation will do. If you are unsure how to set this up, you should go through the tutorial found by clicking “tutorial” in the “HELP” dropdown of the menu bar of TyranoBuilder.

Now, let’s let’s assume that we want our choice to affect the tone of a character’s dialogue without having to create separate Labels for every line that they speak.

First under your YES label, place a TyranoScript box with the line:

1. [eval exp=”f.YukoLoveMeter=f.YukoLoveMeter + 1″]

This line creates your variable and then add + 1 to it. So variable YukoLoveMeter now equals 1.

And if you want, you can create a similar line under your NO label, however that won’t be necessary for this tutorial. But if you do, it should be set equal to 0 or add a minus sign to subtract a point.

Your end up to this point will look something like this:


Pictured above: Simple Yes or No question that affects the variable “f.YukoLoveMeter”

Now we’re using the variable YukoLoveMeter to keep track of how much the character Yuko likes us. And let’s assume we wish to keep it above 0. However at this point subtracting points would cause us to go below. So we would use an IF statement.

In the TyranoScript box under your NO label:

1. [if exp=”f.YukoLoveMeter > 0″]
2. [eval exp=”f.YukoLoveMeter = YukoLoveMeter – 1″]
3. [else]
4. [endif]

We have just created an else if Statement. This script basically says “If YukoLoveMeter is greater than 1 then minus 1, otherwise end questioning.”

*tip: For cleaner code records, declare your variables at the beginning of the game by placing a TyranoScript box at the start of your timelines.*

Now let’s use the variable to affect dialogue by usingTyranoScript box.

Placed somewhere after our YES AND NO text branches, you will want to place the Tyranoscript Box that you’ll be using. You can place this under COMMON label If you’re using the file you created during the Tutorial found under the HELP section of TyranoBuilder.

1. [if exp=”f.YukoLoveMeter == 1″]
2. #Yuko
3. Come along then you amazing wonderful human being![p]
4. [else]
5. #Yuko
6. Ugh. Come along then anyway, you sad sack of garbage.[p]
7. [endif]

IF ELSE script under COMMON label.

This example checks to see if your love is equal to 1, and then displays the text immediately below (but before the ELSE) if this is true.

The [p] contained at the end of the dialogue text tells the game to clear the text after the player “clicks.” If you don’t include this tag, the game will automatically run your lines together during the next set of dialogue lines.

Alternatively, you may also use the [l] (lowercase L) tag to create a pause, that will then continue the next line of dialogue on to the same line. This is a perfect tag to use for those times you want to create a pause in speech without clearing the text. You can also use the [r] tag, which will display the next on the next line beneath it. It’s important to note that the [r] tag does not wait for a user click so it must be used in conjunction with the [l] and [p] tags if you require that pause there.

These 3 tags can be combined on to one line to interesting effect. Such as this following example.

1. #Yuko
2. Hello [l][r]
3. Hello? I’m Talking to you! [p]
4. #
5. Oh. I didn’t see you there. I was too busy learning how to make a visual novel. [p]

These are just 3 of the message tags available. Be sure to check out the developer’s documentation, as it describes how to do other cool such as display an inline image within your text by using the [Graph] tag.

For those who are not coders, take note that instead of using just 1 EQUAL (=) sign, I used 2. This is an important distinction as a single “=” sign is used to assign a value, while the dual sign (==) is used to compare a sign. These are called OPERATORS.

Alternatively I could have used ” > 0″ to see if it was greater than 0. Or I could have written instead of “>= 1 ” to check whether the YukoLoveMeter is AT LEAST 1.

And if you wanted to a get little more complex in narrowing down number ranges, you could say something like:

1. [if exp=”1 < f.YukoLoveMeter < 10″]

This asks “is Yuko’s Love meter greater than 1 but less than 10?”

Sometimes there will be instances where it is required that multiple conditions be true at the same time. This might be the case in a time when an in game item such a box of chocolates might affect the behavior of another character.

To achieve this you would write:

1. [if exp=”f.YukoLoveMeter == 1 && f.ChocolateBox == 1″]

This says “if YukoLovemeter equals 1 AND ChocolateBox equals 1”

Or if I only needed one or the other to be true, I could write

1. [if exp=”f.YukoLoveMeter == 1 || f.ChocolateBox == 1″]

With “||” being the operator for OR. This could be useful for situations in which the solution to something has multiple ways of being achieved. In this hypthothetical situation, the player may be trying to get in to an exclusive club, and it’s required that either the love interest Yuko likes the player a lot OR that the player has something to bribe Yuko with, in order to be let in.

You could also compare two variables.

1. [if exp=”MyVar1 > MyVar2″]

TyranoBuilder and Tyranoscript use basic programming operators such as these – so almost anything you can do in jscript, you can do in TyranaBuilder. For a full list of Jscript operators and their meanings visit:
[link]
[link]

Additionally, you can find out more about Tyranoscript Tags on the developer’s website at:
[link]

Creating a Random variable

In the last section I talked about assigning numbers to variables and using them in an IF statement tree. Now in the section, I would like to talk a little bit in depth about assigning random numbers to your variables.

I was originally going to just throw this in to the first section, however I felt that it needed its own section, because while the syntax all fits neatly on one line of TyranoScript, it may still prove much more confusing to a beginner.

In jscript, the syntax to call a random number looks like this:

1. Math.random()

This creates an absolutely random number that may look like “0.3453155351” – it doesn’t usually spout out whole numbers.

So we would want to use something more like this:

1. Math.floor((Math.random() * 100) + 1))

Math.floor is a method that tells the computer to round a number down to its closest integer. In this case, the number arrived at by the equation within the parentheses which would be ((Math.random() * 100) + 1))

To break it down in its entirety, the equation is stating “round down the random number that will be between 1 and 100.

You don’t need the +1 at the end there, however you will need it if you wish to start at 1. Without it, your number would be between 0 and 99, because computers start counting at 0.

Ok, so hopefully I haven’t lost you yet, because here is how to apply knowledge in order to assign a random whole number to your variable

1. [eval exp=”f.MyVal = Math.floor((Math.random() * 100) + 1))”]

And it’s that simple.

And a simple snippet of code to generate a random number and then check it would look like:

1. [eval exp=”f.MyVal = Math.floor((Math.random() * 100) + 1))”]
2. [if exp=”f.MyVal < 51″]
3 Your number is less than 51.[p]
4. [else]
5. Your number is greater than 50! [p]
6. [endif]

And of course if you wanted to display your random numer in your dialogue, you would use the [emb] tag.

1. [eval exp=”f.MyVal = Math.floor((Math.random() * 100) + 1))”]
2. #Yuko
3. Your random number is…[l]…the number [emb exp=”f.MyVal”] [p]

Pictured: a random number is generated and then embedded in Yuko’s dialogue.

You could use this to create a mini game of chance within your game. The possibilities are endless!

To learn more about random numbers, and Jscript visit
[link]

Creating and Calling a Text Variable

Although simple to do, creating a Text variable receives its own section because creating one requires a different set of tags. It requires the use of a [iscript] tag aka JavaScript tag within your TyranoBuilder tag. Or alternatively you can place a Javaacript Tag directly on your timeline and edit from there, however this is the method I am using for the sake of this tutorial.

Text Variables are very useful for storing the names of people, items, etc. Or whatever non numerical value you wish to store. They can also be used to store arrays, which are a set values stored within a single value.

To create your text variable use the following TyranoBuilder code:

1. [iscript]
2 f.MyVal = [“Lottery Ticket”];
3. [endscript]

In this example, the [iscript] tag tells TyranoBuilder that this this is where Javascript starts, while the [endscript] tag informs TyranoBuilder that this where the Javascript has ended.

As for Line 2 of our example, you can that the declaration of f.MyVal differs radically from the way we have been declaring Integers. It is not enclosed within a tag, and it is followed by a semicolon.

This is real Jscript syntax here, folks. Which I am going to devote the next few lines to talk about now where TyranoBuilder and true Jscript seem to diverge.

While the syntax of line 2 is correct, the following would also be a correct too

1. var f.MyVal = “Lottery Ticket”];

Pictured: Using [iscript] tags to create a Text variable in Tyranoscript

NOTE TO CODERS: TyranoBuilder does not seem to accept the use of “var”, which is used to declare a variable, so don’t use it.

And for you non-coders, be sure to include the semicolon at the end of every line of code within your [iscript] tags. This denotes the end of a line.

Arrays are created the same way using this method. And look like this:

1. f.MyVar = [“pizza”,”milk”,”beer”];

A series of items contained in quotes, separated by commas.

Now, In order to display your variable, you will use the [emb] or EMBED tag inside of your regular old TyranoScript:

1. #Yuko
2. Would you like to buy a [emb exp=f.MyVal] [p]


I hope this helps!

And to learn more about arrays, which is outside the scope of this tutorial (currently), visit W3C’s “using arrays” section at:
[link]

The developer’s documentation also provides an array example for the section on the [preload], which is used to preload images.
[link]

SteamSolo.com