How to enter the game industry (part 5: Ren'py More 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
<< Part 4: Ren'py Scripting

I hope you had enough training with jumps, menus and labels since the previous part, in this part I try to introduce the rest of non-visual commands so we can go straight to visuals in the next part.
more.jpg


Call
We left off with "jump" in the previous part, it's appropriate to open this part with another kind of "jump" called "call".
A call command is pretty much like a jump with a major difference.
A jump is like jumping into a river, you can't get back to where you were when you jumped. A "call" is like telling your buddy "hold my beer while I go pinch a lemon behind that tree."
With a "call" the engine puts a bookmark where you left for another "label" and will return you to that bookmark when you reach a "return" in that "label".

label start:
    "So we where drinking..."
    "Hold on I need to pee"
    jump peeing
    "What was I seeing?"
    "Ah.. the beer was..."
    return

label peeing:
    "Man I need to do something"
    "Something productive"
    "Like kicking a homless guy"
    "oh I'm done"
    return

Run that and see which lines you'll go through. He wondered into the woods didn't he?

Now let's try the same scenario with call:

label start:
    "So we where drinking..."
    "Hold on I need to pee"
    call peeing
    "What was I seeing?"
    "Ah.. the beer was..."
    return

label peeing:
    "Man I need to do something"
    "Something productive"
    "Like kicking a homless guy"
    "oh I'm done"
    return

right back where he left off.

A "call" is pretty convenient for bringing in an event in middle of the story, A "jump" is usually used for branching the story into different routes. Just keep in mind that there needs to be a return at the end of a called label, otherwise it will continue to the end of the document and becomes like a jump.


Variables
It's time for some serious programming then, don't worry variables are not as hard as they sound, You can look at them this way, I have a box named "something" and I can store things in it, It can contain a number, a text or more than one of them.
So you want to count how many times the player have done something? You need to count each time he done it and write it somewhere. Let's go to the example.

label start:
    $ gold_coin = 0
    label ask_for_coin:
        "I have [gold_coin] gold coins"
        menu:
            "do you want to give me a gold coin?"
            "yes":
                $ gold_coin = gold_coin + 1
                jump ask_for_coin
            "no":
                jump no_more_coins

    label no_more_coins:
        "ok then"
        "I guess I'll have to make due with [gold_coin] coins"
        return

Hey, that got complex in a blink, and there's something different in that menu.(you might say)

Don't worry I'll explain:

  • in the 2nd line we made a variable with a value of 0 by "gold_coin = 0" the $ is there because this line is python code and anytime you write a python line of code inside a label, you need to put a $ in front of it for engine to recognize it's python.
  • in the 3rd line we showed the the value of "gold_coin" inside a dialogue by putting it inside a []
  • 4th line is just a menu
  • 5th line is new, whenever you make a menu you can show a dialogue in the chat simultaneously, it can be from narrator or a character and it's usually a question related to the choices. notice that dialogue has no : at the end.
  • 6th line: the first choice
  • 7th line: here we add one to the current value of "gold_coin" the $ indicates it's a python line.
  • 8th line: we jump back to the label "ask_for_coin" to repeat the whole thing.
  • 9th line is the other choice
  • 10th line: if no is selected this jump will take us to the "no_more_coins" label and the rest is pretty clear.

There are another way(s) to define(make) a variable. for example like this:

default gold_coin = 0
label start:
    label ask_for_coin:
        "I have [gold_coin] gold coins"
        menu:
            "do you want to give me a gold coin?"
            "yes":
                $ gold_coin = gold_coin + 1
                jump ask_for_coin
            "no":
                jump no_more_coins

label no_more_coins:
    "ok then"
    "I guess I'll have to make due with [gold_coin] coins"
    return

What's the difference? (you might ask)
Well, the variables defined inside labels are valid inside those labels, any code outside of those labels can't access them, by defining those variables outside the labels you can use those variable for other parts of your code like showing the number of coins at the corner of the screen inside the games interface. We are not ready to jump into the interface topic yet.


if
(Hey what if we want to ask for a specific number of coins before we let them pass?)
Good question, here's where we need "if" to check a condition and decide to do something or another.

default gold_coin = 0
label start:
    label ask_for_coin:
        "I have [gold_coin] gold coins"
        menu:
            "do you want to give me a gold coin?"
            "yes":
                $ gold_coin = gold_coin + 1
                jump ask_for_coin
            "no":
                jump no_more_coins

    label no_more_coins:
        if gold_coin < 5:
            "you don't have enough go beg for more"
            jump ask_for_coin
        "ok then"
        "I guess I'll have to make due with [gold_coin] coins"
        return

Put this code into your editor, line 14 checks if the player has less than five coins and if the condition is true, it runs the indented lines under it, (remember indentation?) and if the user have five coins or more it will ignore the codes under it and skips to the next line. pretty simple right? let's make it complicated.

default gold_coin = 0
label start:
    label ask_for_coin:
        "I have [gold_coin] gold coins"
        menu:
            "do you want to give me a gold coin?"
            "yes":
                $ gold_coin = gold_coin + 1
                jump ask_for_coin
            "no":
                jump no_more_coins

    label no_more_coins:
        if gold_coin < 5:
            "you don't have enough go beg for more"
            jump ask_for_coin
        else:
            "ok then"
            "I guess I'll have to make due with [gold_coin] coins"
        return

What's the difference? (you might ask)
In this case nothing but you should know that "if" is not alone, "if" often comes with an "else"
It's pretty self explanatory, if this condition is true do this, else do that.

What if we want to check for two conditions? making sure he didn't take too many coins? (you might ask)
For that we have "elif" it's a combination of "else" and "if", check this example:

default gold_coin = 0
label start:
    label ask_for_coin:
        "I have [gold_coin] gold coins"
        menu:
            "do you want to give me a gold coin?"
            "yes":
                $ gold_coin = gold_coin + 1
                jump ask_for_coin
            "no":
                jump no_more_coins

    label no_more_coins:
        if gold_coin < 5:
            "you don't have enough go beg for more"
            jump ask_for_coin
        elif gold_coin > 8:
            "hey you're not going to take those extra coins home"
            $ gold_coin = 5
            "I'll take all of your coins"
        else:
            "ok you got enough"
            $ gold_coin = gold_coin - 5
            "I'll take 5 and leve you [gold_coin] coins"

        "I guess I'll have to make due with [gold_coin] coins"
        return

Keep in mind that codes are executed from top to bottom. in this example:
line 14 checks: if gold_coin is smaller than 5, it executes the lines under it.
if it's not smaller than 5 then line 17 checks if it's bigger than 8, it executes the lines under it.
if neither of those conditions are true, the lines under "else" will be executed then it goes to the next line of code. note the indentation.

What else can an "if" check for?
There are a number of operations that if can check for, I'm going to list the ones that you'll end up using the most.

OperatorMeaningExample that the answer is true
<Smaller thanif 2 < 3:
>bigger thanif 3 > 2:
==equal toif 2 == 2:
!=not equal toif 2 != 3:
>=bigger or equal toif 3 >= 3:
<=smaller or equal toif 3 <= 3:

Note that there is no single = in "if" operators. that's because a single = is used for assigning value to a variable and if you use it as an "if" operator it will throw an error.

Let's throw in another currency:

default gold_coin = 0
default silver_coin = 0
label start:
    label ask_for_coin:
        "I have [gold_coin] gold coins and [silver_coin] silver coins"
        menu:
            "do you want a gold coin or a silver coin?"
            "gold":
                $ gold_coin = gold_coin + 1
                jump ask_for_coin
            "silver":
                $ silver_coin = silver_coin + 1
                jump ask_for_coin
            "neither":
                jump no_more_coins

    label no_more_coins:
        "you need 2 gold coins and 3 silver coins to pass"
        if gold_coin < 2 or silver_coin < 3:
            "you shar not pass with [gold_coin].[silver_coin]"
            jump ask_for_coin
        else:
            "ok you got enough"
            "I'll let you pass"
        return

I think you can understand the changes by this point, we have a new variable and an additional menu option to obtain it. the big difference is we have two condition to check but only one "if" and the line just got bigger.

It's pretty simple, in line 19 we have two condition checks:
gold_coin < 2
silver_coin < 3
And there is an "or" between them. this "or" says if either of those two conditions is true run the code below that will return the player to begging.
You can check for multiple conditions with one line of "if" using the operators below:

OperatorMeaningExample that the answer is true
andif both conditions are trueif 2 = 2 and 2 < 3:
oreither of the conditions is trueif 2 = 2 or 2 = 3:
notif the condition is not trueif not 2 = 3:

You can make pretty complex conditions by combining those operators :

if your_money > 100 and not my_dog == "dead" or your_money > 100 and  my_money <= 500 and my_cat == "sick":
    "here, Have my cat for 100 gold"

well fluffy, I needed the money.


I guess that's everything we need to torture the players and stop them from clicking through the game without reading, now you can quiz the players and let them pass only if they answered what did the "Orc" said about "Iron-weed". Now go out there and make something, experiment and get into trouble. I'll be here to help.

Next part we will talk about how to add images into the game, It's going to get visual, and there will be a whole another dimension added to your game. ^_^

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 like your post but I haven't understood which language you have mentioned and how you have done it ? thank's to share it with us !

It's python but In these series of tutorials you don't need to learn the language first, You'll learn how to make your first game and on the side you'll learn enough of python whenever you need to.
However, you need to follow the series for that, on top of each part there is a link to the previous part you can follow all the way to the first one. and another link on bottom of each part leading to the next.
I suggest starting from the beginning

It's great thank you I will read your first part to take an idea how to make games and I will give you my opinion about it thank's again

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 64420.25
ETH 3150.23
USDT 1.00
SBD 3.99