Boolean variables are used always and everywhere!
A variable is a container with information (number, text, etc.). A boolean variable is a switch that can be in one of the following positions: True or False.
In a visual novel, a boolean variable can, for example, store the player's choices for future use. For example, the hero of the VN can remember the player's answer, and in another part of the game act differently.
# Let's create two new logical variables. One with value Fasle, another - True
default orders = False
default my_answer = True
# You can change the value of a variable at any time in the VN.
$ orders = True
$ my_answer= False
# VN can perform some actions depending on the value of the variable.
if orders :
"Perform actions if orders variable is set to True."
"You can also write if orders == True:"
else:
"Perform actions if orders variable is set to False."
if my_answer == False:
"Perform actions if my_answer variable is set to False."
else:
"Perform actions if my_answer variable is set to True."
In this tutorial we will start changing the appearance of a visual novel. We will change the icon that is displayed on the taskbar and in the window title bar. We will also change the game description in the “About” menu.
In this tutorial we will continue to change the appearance of the visual novel.
Now we'll add images in the main menu and in-game menus.
In addition, we will add music in the main menu, so that it wouldn't be so boring.
Let's continue with logical variables and conditions.
In this lesson, I'll show you a couple more uses for variables. You'll learn how to make more complex choices, as well as how to create secret choices that only appear under certain conditions.
# You already know that checks are made by the 'if' command. For example, if 'my_var:' checks if the value of my_var is True, and in this case performs the specified actions.
# But in conditions, you can combine any number of variables to create complex conditions.
# For this purpose, there are special operators and, or and not.
# The following condition checks whether both variables action1 AND action2 are True
if action1 and action2:
# The following condition checks whether at least one of the two variables action1 OR action2 is True
if action1 or action2:
# You can combine 'and' and 'or' in the same condition. But note that 'and' is checked first and then 'or'. Just as in math, multiplication is done first and then addition.
# You can change the checking order by using parentheses, the same principle as in math.
# The following condition will work if the action1 variable is True, or simultaneously the action2 and action3 variables are True.
if action1 or action2 and action3:
# And this condition will work if at least one of the action1 or action2 variables is True, and at the same time the action3 variable is True.
if (action1 or action2) and action3:
Some games allow the player to come up with a name for their character. How to make text input in RenPy? How to limit text input in this case, so that the player does not enter random characters or leave the name blank?
# When declaring a character instead of the name we can write a variable in square brackets that will contain the name of thi character
define my = Character("[myname]")
# You can then spell out the default name
default myname = "Bobby"
# To enter player's name do this
$ myname = renpy.input("What is your name?").strip()
# .strip() - this part is optional, it removes spaces before and after the name
# To specify the maximum number of letters in the name, let's add the length parameter
$ myname = renpy.input("What is your name?", length=15)
# To allow only letters they should be specified in the allow parameter
$ myname = renpy.input("What is your name?", allow="zxcvbnmasdfghjklqwertyuiop-ZXCVBNMASDFGHJKLQWERTYUIOP")
# If you want to suggest a default name, write it in the default parameter
$ myname = renpy.input("Как зовут вашу героиню?", default="Сюся")
# You will now need to write [myname] instead of "Bobby" in dialogs:
my "My name is [myname]!"
# To prevent the player from leaving the input field empty, you can add this condition
if myname == "":
$ myname = "Bobby"
In this big tutorial, we will learn how to format text, which can be very important in a visual novel.
I will show how to display quotes and other symbols, how to make text bold, italic, underlined or strike-through, how to change its size, colour, font and speed of appearance. And moreover, how to insert images into the text.
# To display a quote character, precede it with an \ sign.
"This is just a quote \" and nothing more."
# You can output multiple spaces in a row in the same way
"Spaces - \ \ \ . There are for spaces here."
# \n moves the text to a new line.
"First line.\nSecond line."
# The {b} tag makes the text bold.
"Here is a {b} bold{/b} word."
# The {i} tag makes the text italic.
"Here is a {i}cursive{/i} word."
# The {u} tag makes the text underlined.
"Here is an {u}underlined{/u} word."
# The {s} tag makes the text strikethrough.
"Here is a {s}strokethrough{/s} word."
# You must close the tag that was opened last first.
# This is a correct line.
"Normal {b}Bold {i}Bold-Italic{/i} Bold{/b} Normal"
# This line is wrong
"Normal {b}Bold {i}Bold-Italic{/b} Bold{/i} Normal"
# The {size} tag changes the size of the text
"{size=+10}10 more{/size} {size=-10}10 less{/size} {size=24}Text with size 24{/size}."
# The {color} tag sets the colour of the text
"{color=#f00}Red{/color}, {color=#00ff00}Green{/color}, {color=#0000ffff}Blue{/color}"
# The {cps} tag specifies the speed at which the text appears
"{cps=20}Speed of 20 characters per second{/cps} {cps=*2}Speed twice as fast as normal{/cps}
# The {font} tag specifies the font of the text
"The next text {font=oswald.ttf}uses the Oswald font{/font}."
# The {image} tag inserts an image into the text
"This is my car - {image=car.png}"
This is one of the most important lessons. Playing music and sounds in a visual novel.
With the addition of music, the visual novel will immediately come to life, and so it is important to match the right tunes to the different events of the game.
# Adding music to the script
# Let's add "mu_music.mp3", which is in the "music" folder
define audio.mymus = "music/mu_music.mp3"
# Adding sound effects in the same way
define audio.mysnd = "music/boom sound.mp3"
# Start playing music
play music mymus
# Stop music :)
stop music
# Stop music with a 2-second fade out
stop music fadeout 2
# Playing sound effect is as easy
play sound mysnd
Thanks to numerical variables, you will be able to enrich your visual novel with various details. With the help of numbers you can implement money, health, attack and defense, and other character stats.
# Create a variable like any other
default myhp = 100
# You can convert a text variable (e.g. entered by the player) into an integer by int() function.
# This must be done if you want to perform operations on this variable (addition, multiplication, etc.).
$ myvar = int(myvar)
# You can change the value of a variable with a number or another variable at any time.
$ myhp = myhp + 15 # add 15
$ myhp = myhp - atk # subtract the value of atk variable
$ def = def * 2 # multiply by 2
# You can compare numeric variables in conditions. > more. < less. >= greater than or equal to. <= less than or equal to. == equal. != not equal.
if a > b:
if b <= 150:
if c != 0:
# You can make a chain of conditions using the following construction
# The else block can be omitted.
if a > 100:
# if a is greater than 100
elif a > 50:
# otherwise - if a is greater than 50
else:
# in other cases
You can use the same label many times and get different results! To do this, you will need to call a label with different parameters. Using label parameters, you can make more complex visual novels.
# The label is called with the call command. After the label is completed, the game will move on from the next line after the call.
# In brackets, you can specify the parameters that we pass to the label using commas.
call take_fruit(2, "apples")
# When creating the label, we write the names of variables in brackets, into which the parameter values will be written.
label take_fruit(number, fruit):
# Now in the label itself we can use these variables.
# Display the message ‘You found 2 apples!’
"You found [number] [fruit]!"
# Increase the fruits_have variable by 2.
$ fruits_have += number
# Write the total amount of fruit the player has.
"Fruit in your bag: [fruits_have]."
# We can call this label any number of times with different parameters.
# "You found 5 pears!"
call take_fruit(5, "pears")
# "You found 1 pineapple!"
call take_fruit(1, "pineapple")
# Now by calling the label we do 3 actions with one command!
# Output two messages and change the value of the variable.