TyranoBuilder Visual Novel Studio

TyranoBuilder Visual Novel Studio

164 evaluări
Adding Basic Variables to your game using TyranoScript
De către Ghost Hustler
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 statements

This 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.
   
Premiază
Adaugă la preferate
Preferat
Elimină din preferate
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 http://tyranobuilder.com/tyranoscript-tags-reference/

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!

4. [else]
5. #Yuko
6. Ugh. Come along then anyway, you sad sack of garbage.

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

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

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!

4. #
5. Oh. I didn't see you there. I was too busy learning how to make a visual novel.


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:
http://www.w3schools.com/js/js_operators.asp
http://www.w3schools.com/js/js_comparisons.asp

Additionally, you can find out more about Tyranoscript Tags on the developer's website at:
http://tyranobuilder.com/tyranoscript-tags-reference/

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.

4. [else]
5. Your number is greater than 50!

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"]


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
http://www.w3schools.com/js/default.asp


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]



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:
http://www.w3schools.com/js/js_arrays.asp

The developer's documentation also provides an array example for the section on the [preload], which is used to preload images.
http://tyranobuilder.com/tyranoscript-tags-reference/#preload

60 comentarii
Ghost Hustler  [autor] 12 ian. 2017 la 9:10 
Zee Shadowfox:
Yes. An array can contain strings and vars. It's just a set of data.

There's a number of ways to do it, but the MATH function seems to be your best answer.
Check out the answers to this question on StackOverflow.

http://stackoverflow.com/questions/1379553/how-might-i-find-the-largest-number-contained-in-a-javascript-array
Zee 12 ian. 2017 la 7:30 
Great guide, one I'm sure I'll be referencing throughout my project.

I was wondering whether you knew how someone would go about writing code to find the highest score in a set of variables. In my example, the main character is rescued by the character who has the highest relationship with them at the time the scene plays.

Is it possible to write something that would compare all six of the bachelors' affection scores and find who has the highest and then jump to their rescue scene? My friend suggested making an array, but can arrays include variables?
Starry☆Dawn 2 iun. 2016 la 3:40 
For making a name input box, when trying to recall it after the "#", what script would I use? Sorry if I'm not describing it correctly.
Ghost Hustler  [autor] 9 apr. 2016 la 22:47 
Mikado - Sorry about the long delay. I didn't receive a notice about your comment for some reason.

While not a bad idea, that's out of the scope of this tutorial, and definitely much more complex! It To make a "Princess Maker" or "Tokimeki" type sim game, you would need to create a set of variables for keeping track of the date, as well as figure out a "routine" set of commands that the player would continuously loop through. Through out you would set prompts for it to check things that would break it out of the loop. Such as "Is today a special date?" etc. If so run a subroutine, then have it jump back in to the loop.

This tutorial should actually contain most everything you need already, it's just a matter of practical application. You may wish to learn the fundamentals of game programming if you're stumped. There's some free classes on JavaScript at EDX.org I think, and Udemy.
The Baekin' Company 22 mart. 2016 la 22:10 
Can you include a section on how to make an in-game calender or time limit?

(for example, Long Live the Queen lasts 40 in-game weeks that function as turns for the player. In Princess Maker, you spend 1 month incraments raising your daughter that add up to a total of 8 years)
Ghost Hustler  [autor] 25 febr. 2016 la 0:12 
As for assigning random #'s to the array...

I suppose if you wanted to assign a random number to something within the array you could have initial set nulls then say something like...

f.Yuko[2] == (random number code);

The point of an array is clean code. So you don't have to create a ton of separate variables; instead you can assign a ton of values to 1 variable. This is an important concept of "object oriented programming." Treating Variables like objects.

Think back to Geometry. To get volume you times Length x Width x H. Those all belong to the BOX. The box is its own variable. Creating an array essentially makes it its own class or object.

f.BOX == [L, W, H];

The Box's Volume would equal f.BOX[0] * f.BOX[1] * f.BOX[2]
Ghost Hustler  [autor] 25 febr. 2016 la 0:00 
No. the array contains those.

So your variable name would be say the name of your character (The var name is symbolic)

So to set Yuko's Name, Favorite Color, and Age you'd do as follows:

[f.Yuko = ["Yuko","Blue", 18]];

As for the Variable manager...as far as I can tell that is TyranoBuilder simplifying TyranoScript for you and not inherent to TyranScript itself. You have more flexibility learning code than you do using the Automation functions here. It's still worth using TyranoBuilder tho as it still greatly simplifies development.
forza-jordan 24 febr. 2016 la 1:27 
This would work as variables for the same character as long as it was coded in under that character. Right?

Just FYI it'd be random using

[eval exp="f.RandomOption=Math.floor((Math.random() * 6 ) +1) "]
[if exp="f.RandomOption == 1"]

Hence why I want more variables for the one character.

But then doesn't it leave you ending up creating dozens of the variables in the variable manager, or is that the point of the manager?
forza-jordan 24 febr. 2016 la 1:27 
What if I wanted variables for his name, his age, his favourite colour and how much dosh he earns or loses per turn (as an example).

[emb exp=f.Character1] = Name
[emb exp=sf.Character1] = Age

Then what?

Would I need to create a new variable in the manager called Character1_B and then do


[emb exp=f.Character1B] = Fave Colour
[emb exp=sf.Character1B] = Dosh

So if character is selected it would go something like...

This is [emb exp=f.Character1]
[emb exp=f.Character1] is [emb exp=sf.Character1] years old.
[emb exp=f.Character1]'s favourite colour is [emb exp=f.Character1B]
Currently, [emb exp=f.Character1] earns [emb exp=sf.Character1B] per turn.