NokiMo
JPDE
JPDE

patreon


Renpy Tutorial 04 - Dialogue, Labels, Branches

https://youtu.be/4erbf-t0ohc

Hello thar, Meinos Kaen here… And welcome back to my tutorial video series for making games in Ren’py. This is the fourth and last in the Basics Series. After watching all of these four in sequence, you will have all you need to go out there and make your own Basic Visual Novel games with Ren'py!

This is not the last video tutorial I'm going to make, but the next subjects will be a little more variegated and specific, now that we covered the basics. Also, subscribers to the JPDE Patreon will be able to vote and choose the subject of each new video! And I hope you have joined our Discord Academy, as I have a lot of fun plans for the future. Finally, starting from this video onwards, I will always be posting them –publicly, so anyone can see them even without being a paying member- on the JPDE Patreon page first.

With that said, today's lesson is all about writing! We've skimmed over it a little in the previous lessons, but today we're going to unlock its potential! You will learn:

-           What Text Tags are and how to use them with Character Speaker Objects

-           What labels are, and how to use them to alter the flow of a script

-           How to use Choice menus and branch scripts

Let's go!

DIALOGUE TEXT TAGS

We've been using Dialogue regularly in our test game. We even made a fun Tsukkomi routine with Penny and Blake... Now, though, what if we want to exert a little bit more control on how dialogue looks and is presented to the player? Say we want some words to be bold, a different colour, bigger, add some special characters... How do we do that? With Ren'py's Text Tags!

If you've ever been on a forum-like website, you have certainly ran into BBCode –otherwise known as Bulletin Board Code- formatting. For those who don't know, it's a way which allows you to tell a Forum 'I want this particular text to look like this' when making a post. Ren'py's text tags work very similarly, with the difference that in BBCode you use square brackets, while in Ren'py you use curly brackets.

Let me show you with an example. Let's say that we want to give some emphasis to this piece of Penny's dialogue. To do that, we need to place two specific tags in two specific places: one at the beginning and one at the end of the text you want to change. I've linked the list of tags from the official Renpy documentation in the description but, for now, let's just make it Bold.

So, we go here and... We open curly brackets... And then we write down b, lowercase. That's for 'bold', we're telling Ren'py that the text after this text tag must be made bold. Then, we go to the end of the text we want to make bold, and again... Open curly brackets... Then forward slash –FORWARD SLASH, do not use the backwards slash, it's important-... And finally, lowercase b again. This text tag tells Ren'py that, from this point on, we do not want the text to be bold anymore.

And that's it. It's that simple and all text tags follow the same logic. You open curly brackets and put in the appropriate symbol –and depending on the specific text tag, some extra information-, and you do the same at the end of the text you want to change, while adding the forward slash to symbolize the end of that specific text tag effect. Let's see how it works...!

Voila. As you can see, the only part of the text that was made bold is the one wrapped between the text tags we've just used... Let's try and combine a few now, let's have fun.

Let's say on this Blake line here, we want to make the last part italicized, and also we want a part of that italicized text to be... Smaller. A smaller font size than the rest of the sentence, which uses the default size. How do we combine the two text tags?

First, we add the tags for italics which use the symbol 'i'. Open curly brackets and write i... Then, go to the end of the sentence... Open curly brackets, forward slash, i again. This entire bit of text will now show up in italics, but we also want this part of it to be smaller in size.

So, we go back to the beginning of the snippet... Open more curly brackets... we write 'size', which means we're altering the size of the font, but it's not enough. We also need to tell Ren'py the new size we want the text to be. So, we add the = sign... And afterwards, an integer number which will be the new size. In this case, let's say... Twelve.

And then, when we want to cancel the new size effect, we go at the end and... Open curly brackets... forward slash... size. No need to give more info, because all we're doing here is telling Ren'py to stop it and go back to the default size. Save, always save... And let's test it out!

What a delightfully passive-aggressive kitty you are, Miss Belladonna! Playing around with text tags is fun, isn't it? I'm not going to go through all the different text tags, you can find them in the link I put in the description. Grab the ones you like and go nuts!

There's a couple more things I want to show you, though. First, how to use special characters or, as Ren'py calls them, Escape Characters. These are special commands that allow you to put in types of text you otherwise couldn't, as the Ren'py code language would interpret them as parts of the code.

For example, let's say we want to add quotes at the beginning and at the end of the dialogue strings. I like to do this myself, to differentiate spoken dialogues from descriptions, narrations, etc... It's a stylistic choice. But, as you can see, in Ren'py quotes are used to delimitate strings of text, so using more quotes in the normal way would mess up our code.

So, we need a special 'escape character', and that translates to... Writing backslash –not Forward slash like in the text tags, this is why you need to pay attention! - and then... The quotes symbol. That's it. Seriously! Don't believe me? Let's add them at the end as well, and do the same for the following line, and I'll show you! Backslash and quotes, backslash and quotes, backslash and quotes. Aaaand save...

See? It's really that easy! There's other characters that respond to this need, and you can find the list in the same link where you can find the text tags... But, I know that the more observant of you are going to say: wait, that sounds TEDIOUS. You put quotes in front of and after every single line of spoken dialogue? That means writing those symbols in every single time!

Well yes... And no. Because, see, there is a way to tell Ren'py to always add specific things to any line of dialogue spoken by the same speaker object... Remember when we defined them, back in lesson one?

When we created Penny's speaker object, and then Blake's speaker object, We made them pretty barebones. We just gave the object the name to display, and the symbol we'll use to call it whenever we want... But thing is, speaker objects are INCREDIBLY versatile. There's a lot more variables we can influence, here. For the purposes of this lesson, all I'm going to show you is: how do we tell Ren'py to always put the same string of text in front and at the end of every line of dialogue for a speaker?

Like this.

Let's say that we want Penny and Blake to always have quotes when they speak. Let's do Penny first... We go back to the speaker object. After the code that tells us the name to display, we add a comma... Then, the variable name... what_prefix. This command takes a string of text between quotes, as a value, and it tells Ren'py 'hey, ALWAYS add this at the BEGINNING of a line of dialogue'. Just like a prefix!

Then, we add the equals sign... Then, we open quotes... And inside the quotes, we write down the escape character for the quotes symbol. Backslash... And then, quotes. That's it! And to add them at the end, it's the same process, with one simple difference.

We add a comma, and then the command is... what_suffix instead of prefix... then equals sign, open quotes, backslash and quotes symbol. Voila! Done! That's it! Let's copy paste to add it to Blake's speaker character as well... Then we save... And let's test out the game again!

Ta-daaaaa! It works! And since I didn't remove the backslash quotes that I had put in by hand in those two first lines of dialogue, they doubled up! Because Ren'py sees the what_prefix and what_suffix variables in the speaker character, and then sees the individual quotes we added in the single line of dialogue... And adds them both.

This saves me so much time, you have no idea. I have some speakers which are for thoughts, so they are all in italics. Others for phone conversations, which are of a different colour and underlined, and so on... And there's a lot more things you can do with tags and speaker objects. Maybe we'll go into them in a future lessons? You decide!

For now, let's move on... To Labels.

LABELS AND FLOW

We touched upon Labels in the first video. I explained how they're 'addresses' which can guide you –and the player- to certain parts of the script. Right now we only have one label in the entire test game, and that's the default label 'start', which any new game will automatically jump to. It's now time to make our own labels and use them!

Let's go at the bottom, after Penny has smacked Blake on the head for disrespecting Visual Novels. We're going to add a new label on a new line before 'return', which would cause us to go back to the title screen. And we do it by simply writing 'label'... all lowercase, then a space... Then, a unique name for the new label. If you have two labels with the same name ANYWHERE in your script, Ren'py is going to give you an error and not start the game next time you try and run it.

We're going to call this new label 'violence', and then follow it up with a colon. Everything underneath this label will now answer to a new 'address', and must as always be written tabbed once to the right. I'm going to write a little follow-up from the previous scene where Blake reacts by squaring up...

There we go. Now, as you remember, Ren'py always reads a script from top to bottom so, even if the code becomes affiliated with a new label, it will keep on going until it cannot anymore. So let's save and see what happens.

As you can see, the code just continues from top to bottom, through the new brief addition to the scene, and then stops once it hits the return command. Now... I want to add another scene under a new label, where Blake instead 'thinks' about getting back at Penny by choosing violence. And this time, we're going to add it in a new script file!

So we create a new file, let's call it... story_01.rpy. Then, inside, we're going to add a new label by writing label, space... Let's call it 'pondering'... And then a colon. Then, underneath and with a tab to the right, I'm going to add a couple lines of dialogue where Blake thinks about how to react to this affront! And voila'. Now, though, as this is in a different file, Ren'py won't go there automatically. We need to tell the engine 'hey, I want you to go here, now'. And we do that... With the 'jump' command.

It's pretty self-explanatory, isn't it? The 'jump' command tells Ren'py to 'jump' to a specific label. Let's go back to script.rpy, to the line right before the 'violence' label. We make a new empty line, and we write... jump... space... followed by the name of the label we want the engine to jump to, in this case: pondering. And that's it! Let's test it out!

As you can see, instead of going further down the code in the script.rpy file, Ren'py obeys the jump command and goes to the pondering label, continuing then to go down the code in this new file. Then, at the end of the code, as there's no more instructions, it goes back to the Title Screen, as that is default. It's really easy, isn't it? And now, I'm going to shock you with special effects!

Question for the class. Let's say that, after going through the pondering lines, we want to continue down the code in script.rpy and see Blake actually get into fisticuffs with Penny. How would you do that? If your answer was 'let's just add jump violence' in the code, you would be absolutely right! That is, indeed, an answer. Let's test it out!

Good job, class! You've cracked the code! But here's the thing: there's an alternative way of doing this that may be better suited for certain situations, which uses a different pair of commands... One of which is our little friend 'return'. The truth is, return doesn't specifically send you back to the title screen. It's a generic command that tells Ren'py to go back –return- to the last place it came from... And it creates a very powerful duo with the other Ren'py command 'call'.

First of all, here in story_01, we're going to remove the jump violence line... And replace it with the simple command 'return'. Then, back in script.rpy, we're going to switch 'jump' with 'call', so the line now reads call pondering. Call is a command that can be used with many things, not just labels, but when using it like this in conjunction with the 'return' command, it means that Ren'py will jump to the indicated label, run through the script and then –when hitting the return command- will jump back here: to the same line of code it jumped from, and continue down like nothing had happened.

This is very powerful and very useful because the jump command only works with other labels. Call and return, instead, works on any line of code. I use it a lot with stuff like battle systems, where I have a bunch of commands or functions that need to be ran before any random battle, so what I do is: put all those commands under a single common label followed by 'return', and tell Ren'py to call that label every time a new battle begins. Let's see how it works here!

Just like with the more articulate jump forward and back, Ren'py goes to the pondering label, goes through the increasingly murderous thoughts of Blake Belladonna and then back to script.rpy to see the outcome! Master Jump and Call/Return, and you will be able to do so many articulate things once you start mastering variables!

And finally, the last thing. The last bit of the last video of this four part starter series... Is Branches and Choices. The meat and potatoes of a Visual Novel.

BRANCHES AND CHOICES

If you've ever played a non-Kinetic Visual Novel, you've come across the concept of routes. They're normally tied to specific characters, and ending up on one is usually due to narrative or gameplay but, bottom line is: at certain points in the game you're asked to choose between option A or option B... Or C, D, E, etcetera. Point is, Visual Novels usually ask you to make choices! So, how do we code those choices in?!

Here's how.

What we need to do is use a special kind of label called 'menu'. I call it a special kind of label because menus –while not required- can have individual names, and you can jump to a menu using the jump command! So, while the most basic menu would simply be created like this... writing menu followed immediately by a colon... I personally like to always use them as I would a label: writing them on the same tab level as labels, all to the left, and giving them individual names so that I can jump to them whenever I want.

So here's what we're going to do. At the bottom, underneath the violence label, we're going to add a new label, called 'knowledge'. Underneath, we'll have Blake choose to re-evaluate her opinion of Visual Novels instead of striking back against Penny. Then, another return because in either case, we want the game to go back to the main screen after they're done talking.

And underneath all that, we're going to create our very first menu! As aforementioned, we're going to have it on the same tab level as a label, so we tab left once... Then we write: menu... then space... then the name of this specific menu, which we can call... kitty_choice... And then, a colon. Now, underneath, we must code the choices that are going to be available to the player. We want to make one that is going to bring the player to the violence label, and another that is going to bring the player to the knowledge label.

First of all, we need to add between quotes a string of text, which is going to be the displayed text of our choice. Since this is the choice that will lead us to the violence label, we'll write... "You realize this means war". There. We then add a colon, and we go below to the next tabbed line... And here, we need to add lines of code that will only be read if the player chooses this choice. In this case, we're going to add the simple jump violence command. So, when the player makes this choice, he will jump to the violence label.

We're going to copy this, and paste it below... And replace the details we need to make this a unique choice. For the text between quotes, we're going to write... "Maybe I was too hasty"... and below, after jump, we'll replace violence with knowledge. And that's it. We've created a menu with two choices! The last thing we need to do is make sure that the player gets here! Because we wrote this menu underneath the two labels it can jump to, Ren'py won't be able to arrive here just going top to bottom.

Even if it tried, once it reaches the first 'return' command, it will just go back to the title screen... So, what do we do? I'll give you ten seconds to guess... Exactly! As I said earlier, we can jump to menus with unique names like they were labels, so underneath the call pondering line, we're going to add... First a one second pause, for scenic effect... And then jump kitty_choice. And voila! The moment of truth...

It works exactly as we intended! After coming back from the pondering label, Ren'py waits one second before bringing us to the menu we've created! Two choices, each one with the text we've written for them, and each one with a different result. If we choose the first one... Blake chooses violence, and that's the end of it.

But if instead we choose the second one... Blake wants to learn more and get rid of her preconceptions! To be continued!

CONCLUSIONS

Which is, in a way, the choice YOU need to make now! Congratulations, everyone! You've successfully completed the starting course! With these four videos, you now have all the basic tools you're going to need to make your own basic visual novels! If that's all you're interested in making, this is all you're going to need!

But if you want to do more, if you want to learn more. If you want to learn how to use variables, and custom screens. If you want to learn about GUIs and functions. If you want to create Dating Sims and Battle Systems. Calendars, and Time Progression! There's a lot more videos waiting for you, and if you're a paying member of our Patreon, you will be able to vote on the next topic! Finally, I invite you to join the series's official Discord Server! I'd love to see what you're working on, and I will be posting some challenges in the future for you guys~

Be sure to like, comment and subscribe, whether you're on Youtube or Patreon, and I'll see you all... In the next tutorial! Ciao!


Related Creators