How to enter the game industry (part 4: Ren'py Scripting)[tutorial]steemCreated with Sketch.

in #gaming7 years ago (edited)

part 1: your skills
part 2: Choosing an Engine
<< Part 3: Ren'py Game Engine

Now you know a bit about Ren'py engine we can start looking into it's scripting syntax and go over the usual pitfalls new users usually encounter.
0.jpg

To open the main script file of your game click script.rpy while your games name is selected in the project list.
1.jpg

If you configured your editor correctly your script.rpy file will open in Editra.
2.jpg

From here on I will give you what's in the editor:
3.jpg
As a code block like below, you can copy and paste the code into your editor instead of reading and typing.

define e = Character("Eileen")

# The game starts here.
label start:
    show eileen happy
    # These display lines of dialogue.
    "Hello, world."
    e "You've created a new Ren'Py game."
    e "Once you add a story, pictures, and music, you can release it to the world!"
    # This ends the game.
    return

For starter delete everything. Don't worry we will put the essential parts back immediately. Now you have a clean screen put back these 3 lines.

label start:
    
    return

Hint: In python indentation of the code lines is very important, as a rule of thumb anywhere there is a colon ":" the next line(s) are indented with few spaces(usually 4).
In the example above think of "label" as a container named "start" and it has an "empty line" and a "return" command inside if it. you will see an example in the next code block.

So what's that (you might ask):
It's the main label of your game, when you push the start button in your game, it will take you to this label therefore you will need a start label in your game or you'll get an error when you try to run your game.


What are Labels
Labels are like chapters in books, They provide a reference point in the story. there are few rules about labels you need to keep in mind.

  • You can have as many labels as you want.
  • You can have labels within other labels.
  • Labels should have a unique name, two labels can't have the same name. a duplicated label name will throw an error.
  • Labels name can't contain any spaces.

Now we have a label let's add some dialogue, after all the majority of the text would be dialogues exchanged between characters.

What are Characters
Characters are a shorten version of the characters in your story, this shorten version is used to show a dialogue under the name of that character as if that character is speaking.
First we need to define a character, remember the text we removed earlier? there was this line:

define e = Character("Eileen")

It defines a character named Eileen, and the shorten name "e" is used to speak through this character, change your code in your editor to this:

define e = Character("Eileen")
label start:
    e "hi, I'm Eileen, Nice to meet you."
    return

notice the indentation of the dialogue line.
The dialogue lines are usually a shorten version of the characters name followed by an empty space then the dialogue inside quotation marks.

Go ahead and copy that into your editor and replace everything, Now save (CTRL+s) and go to your Ren'py and Launch the project. press start button and see the result. there are few things about characters you need to keep in mind:

  • Characters should be defined outside of any labels therefore, they are usually places at the top of your script file.
  • You only need to define each character once.
  • A character can have extra parameters while defining like the color, size or position of the name or dialogue and many more.
  • I recommend using the three first letters of your character name as the short version to avoid confusion in case you have two character names that start with the same letter.

Hint: to see the result of the change you make in the script you can either close the game and launch it again, or use the auto reload function.
To activate auto reload, while the game is launched and selected press "shift+r" now the game will reload whenever you save the script in your editor. (next block of code, copy, paste, save)

define e = Character("Eileen")
label start:
    e "hi, I'm Eileen, Nice to meet you."
    "This is your narrator speaking"
    return

You also have a special character named "Narrator", it doesn't need to be defined and doesn't need a shorten version, any text in quotation marks will be shown as the narrator, However, you can use:

define Narrator = Character("")

To change the settings on this character or even give it a name. we will open this character creation more at a later time.


Jumps
As I mentioned before your story can have many labels , With jump command you can jump from one part of your story to any label you want. to check this we need multiple labels.

label start:
    "the games start"
    
    label chapter_1:
        "this is chapter one"

    label chapter_2:
        "this is chapter two"

    label chapter_3:
        "this is chapter three"
    
    return

The code in the game will be executed from top to bottom. as you can see the label "start" contains three labels, and the dialogues show one after another. the same thing will happen if those labels are not inside the label "start".

label start:
    "the games start"
    
label chapter_1:
    "this is chapter one"

label chapter_2:
    "this is chapter two"

label chapter_3:
    "this is chapter three"

the game will simply go to the next line till it reaches the end of the code or a return (more on returns later).
now let's put a jump in there:

label start:
    "the games start"
    jump chapter_3
label chapter_1:
    "this is chapter one"

label chapter_2:
    "this is chapter two"

label chapter_3:
    "this is chapter three"

Try the code above, you'll notice the game will skip anything after a jump and goes straight to chapter_3. you might ask: why would I want to do that? well a jump alone don't have much power, but combined with "menus" it will become one of your most powerful tools.


what's a menu
A menu is a choice you can give the player, you can give your player multiple options to choose from and let them decide what the characters should do and where the story should go. (copy, paste, save, run)

label start:
    "the games start"
    menu:
        "go to chapter one":
            jump chapter_1
        "go to chapter two":
            jump chapter_2
        "go to chapter three":
            jump chapter_3

label chapter_1:
    "this is chapter one"

label chapter_2:
    "this is chapter two"

label chapter_3:
    "this is chapter three"

notice the colons after each choice and the indentation after each colon.

To explain it simply this menu contains three options that shows as buttons on screen, each button contains a jump to a specific label.
If you choose the chapter one or two, you'll notice that the game will go through the chapter after them anyways, if you don't want that to happen this is where you can use "return"

label start:
    "the games start"
    menu:
        "go to chapter one":
            jump chapter_1
        "go to chapter two":
            jump chapter_2
        "go to chapter three":
            jump chapter_3

label chapter_1:
    "this is chapter one"
    return
label chapter_2:
    "this is chapter two"
    return
label chapter_3:
    "this is chapter three"
    return

A return will ignore the lines after it and in this case skip to the end of the game.

You can also use jumps

label start:
    "the games start"
    menu:
        "go to chapter one":
            jump chapter_1
        "go to chapter two":
            jump chapter_2
        "go to chapter three":
            jump chapter_3

label chapter_1:
    "this is chapter one"
    jump the_end
label chapter_2:
    "this is chapter two"
    jump the_end
label chapter_3:
    "this is chapter three"
    jump the_end

label the_end:
    "this is the end"

You can also achieve the same effect with less code lines:

label start:
    "the games start"
    menu:
        "go to chapter one":
            "this is chapter one"
        "go to chapter two":
            "this is chapter two"
        "go to chapter three":
            "this is chapter three"
    "this is the end"

but the purpose was to demonstrate how jumps work. I can imagine you're already planing a labyrinth of labels, menus and jumps to torture your players. well start working on them, and start experimenting, you need to encounter those pesky errors coming from missing colons and wrong indentations before we move onto more of commands and functions.

If you're too eager to wait for the next part and you want to learn more you can check your documentation in Ren'py launcher as a powerful guide. And like always, don't hesitate to ask if you had any problem.

part 4: Ren'py Scripting
part 5: Ren'py More Scripting
part 6: Ren'py Scripting, Visuals
part 7: Ren'py Scripting, Dialogue
Part 8: Ren'py Scripting, Conclusion
Part 9: Images
Part 10: Animation
Part 11: sound editing and voice acting

Sort:  

I really enjoyed your post, thank you for sharing with us. Enjoy the vote!

it's great informations really thank's to share this post with us , am waiting to your new posts I have followed you !

Coin Marketplace

STEEM 0.19
TRX 0.14
JST 0.030
BTC 60078.84
ETH 3197.52
USDT 1.00
SBD 2.45