Ren'Py Please help me with my first renpy game.

h0932377128

New Member
Sep 25, 2019
13
3
Hi guys, I am trying to create my first renpy game. Everything for me is very new, I don't know much about python or anything expert. Just know some very very basic code on youtube.

So all the code I know is trying to keep it as basic as possible. I have some questions I hope you can teach me.
here my code:

Code:
init:

       $ Power_Points = 0

       $ Kungfu_Points = 0

       $ Power_Points_Max = 100

       $ Kungfu_Points_Max = 100



define Power_Points = 0

define Kungfu_Points = 0



label start:

         label fighthim:

                   scene fight_him

                   with dissolve

                   if  Power_Points  >= 0:

                       jump lose

                   elif Kungfu_Points >= 0:

                       jump lose

                   elif Power_Points >= 30:

                       jump draw

                   elif Kungfu_Points >= 30:

                       jump draw

                   elif Power_Points >= 50:

                       jump win

                   elif Kungfu_Points >= 50:

                       jump win

                   label lose:

                           scene youlose

                           with dissolve
------------------------------------------------


I tried this code, but it didn't work, the game automatically moved to the lower label without counting the if point statement.
and let me ask is there a way to group the numbers in the "if points statement" code? Because every time I use it, I have to write a very long code like that?
I want to use it to count hours of the day, 24 hours. Is there any way for me to group 6-12 hours into a group? 13-18 hours 1 group? for example:


------------------------------------------------

Code:
 if Hour_Points = 6,7,8,9,10,11,12:
               jump morning
 if Hour_Points = 13,14,15,16,17,18:
              jump evening

-------------------------------------------------



I tried it but it didn't work
 

scrumbles

Well-Known Member
Jan 12, 2019
1,069
1,096
I think the first block can be rewritten like that:
Code:
                   if (Power_Points >= 50) or (Kungfu_Points >= 50):
                       jump win
                   elif (Power_Points >= 30) or (Kungfu_Points >= 30):
                       jump draw
                   else:
                       jump lose
As for the second block:
Code:
    if Hour_Points in [6,7,8,9,10,11,12]:
        jump morning
    elif Hour_Points in [13,14,15,16,17,18]:
        jump evening
(or you can use the "<" operator, like in the first block).

As for the initial statements, I'd drop the "init" block and just write:
Code:
define Power_Points_Max = 0
define Kungfu_Points_Max = 0
default Power_Points = 0
default Kungfu_Points = 0
I would use "default" for variables, "define" for constants.

No need to study Python for now, but some fundamentals of logic are useful. For instance, with your code the game always jumps to the "lose" scene because the first condition is always matched, no matter if the Power Points are equal to 15, 40 or 60. You should have started with the stricter conditions (>= 50) and then checked the other conditions (>= 30, then >= 0).

Please note that I am not a dev and I haven't tested the code, I could have made some mistakes.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,258
One comment I would make is that I think you're indenting too much.
You're indenting each time you reach a new block of code. If you continue with that style... you'll be indenting 100 or 200 characters deep by the time you're around the middle of your first chapter/release.

If I were writing the code... it would looks like this:

Python:
default power_points = 0
default kungfu_points = 0

define power_points_max = 100
define kungfu_points_max = 100

label start:

    scene black with fade
    "<<< START >>>"

label fighthim:

    scene fight_him with dissolve

    if power_points >= 50 or kungfu_points >= 50:
        jump win

    if power_points >= 30 or kungfu_points >= 30:
        jump draw

    # No need to check for values below 30. If we didn't win or draw... we lost.
    # and no need to jump to lose... we can just drop through.

label lose:

    scene youlose with dissolve
    jump the_end

label draw:

    scene youdraw with dissolve
    jump the_end

label win:

    scene youdraw with dissolve
    jump the_end

label the_end:

    "<<< THE END >>>"
    return

The reason you were running into problems was because you were checking for >= 0 before checking >= 30 and >= 50.
If you were writing a list on paper, it would make sense to write 0 then 30 then 50.

Problem is... a value like 60 is greater than 0 and 30 and 50. All 3 checks would be True. So when you check >= 0 first, that's the one that is True first.

I've also removed the capitalization from your variables. Partly it's a style thing. Lots of language have informal "rules" that specific types of data objects or specific types of functions use capitalization and everything else doesn't.
And partly it's because RenPy is case sensitive and will regard Fred and fred as two separate things. The moment you forget to Capitalize one of those names... bad things will happen.
Honestly though, RenPy doesn't care. It could be just habit on my part. Stick to whatever works for you. Just know the moment you mix it up, there's a good chance you'll generate an error. Worse case scenario is that it doesn't generate an error and it takes forever to spot you used a "P" when you meant "p" (or visa versa).

Finally, I've changed all the variables that will change while the player is playing to default and all the variables that will won't be changed (constants) to define.

Short version is that variables created using default are saved in save files and variables created using define aren't. So imagine you've decided to raise the cap from 100 to 150. With define that takes effect immediately the player starts the game. But something setup as default my_var = 100 or $ my_var = 100 would be part of the savefile. So when your player loads an older saved game... you get 100 rather 150... because the savegame values overwrite the previous values.

There's a long boring reason why default my_var = 100 is better than $ my_var = 100 for creating variables for the first time. But given how new you are to RenPy... I'll just go with "trust me... this way is better".

Oh yeah... and I removed the elif's too. They work. But (again, personal preference) I find code easier to read when I only use elif's when they are absolutely necessary. "Clever code" is all well and good, but a nightmare to maintain. The simpler you keep things, the simpler you will make your life in the future.
 
Last edited:

polywog

Forum Fanatic
May 19, 2017
4,065
6,295
The fastest way to learn renpy is to find a game that you like, and dive into it.
Play the game so you know what it does, then look at the code and see how it does it.
Mod the game... change things.

The-Mid-Terms-are-not-a-test-Nobody-cares-if-you-bring-a-cheat-sheet.jpg
 

h0932377128

New Member
Sep 25, 2019
13
3
79flavors
I just woke up. and prepare to test everything. You guys really helped me out, Thank you so much everyone. : *

polywog
I was planning to make a complicated game like summertime saga, but I found a way to make the game simpler my way. Because I see in summertime saga there are many disadvantages and unnecessaryities of it.

scrumbles
I didn't know this, tried to find a way to see the renpy code but no luck. This is really a help to me. Thanks so much again. :*****

It works like beast. thanks everyone. Especially scrumbles and 79flavors. But can I ask just one last question? I plan to make the game have only about 90 days. I have thought of a way but it's quite stupid. That is, create a label where you wake up, and connect the other labels as a repeat version, until the 90th label, then jump to the ending. Like this:
Code:
label Sleeproom:
     menu:
          "Sleep to next day":
                 jump next1
          "Go out":
                 jump outsite
     label next1:
           menu:
                 "Sleep to next day":
                        jump next2
                 "Go out":
                        jump outsite
            label next2:
                    menu:        
                         "Sleep to next day":
                                jump next3
                          "Go out":
                                jump outsite
            ........................................bla............bla
                                                     label next90:
                                                            jump to ending

Something like that, is there any basic code that is easier to use but shorter? Thank you very much.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,258
Okay. My OCD NEEDS me to fix your indenting before I can even think about your overall question.

Python:
label Sleeproom:
    menu:
        "Sleep to next day":
            jump next1
        "Go out":
            jump outside

label next1:
    menu:
        "Sleep to next day":
            jump next2
        "Go out":
            jump outside

label next2:
    menu:       
        "Sleep to next day":
            jump next3
        "Go out":
            jump outside
           
# ........................................bla............bla

label next90:
    jump to ending
Again, it would have worked just fine. But my rough back of a napkin math says by day 90... you're indenting would have been 360 characters deep.

And with that out of the way... let me see if I can get my head around your actual problem.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,258
Okay. First things first...
You can keep track of what day you are up to using an integer variable (whole numbers, no decimal places).
You can also put variables in the middle of conversation text by mentioning them in the middle of square brackets. [ ].

Now a temporary diversion....

I'm going to pretty things up a bit by using the actual day names.
Python (and by extension RenPy) have all the usual math functions... including modulus.

So in the same way "plus is +", "minus is -", "multiply is *", divide is /", "to the power of is ^" ... "modulus is %".

It's not a bit of programming a lot of people touch upon and it's a bit of math most people forget...
... but modulus is the remainder after you divide one number by another.

So 10 divide 5 is 2 reminder 0.
So 10 % 5 = 0

10 / 3 = 3 remainder 1.
10 % 3 = 1

Next... Python (and again RenPy) can use arrays. Arrays are lists of stuff enclosed in square brackets.

define my_array = [1, 2, 9, 8, 8, 7] is an array/list of 6 numbers.
You can access the array in a number of ways... probably the most common is by a numbered index.

my_array[0] is 1.
my_array[1] is 2.
my_array[3] is 9.
and my_array[5] is 7.

As you can see, the index starts at zero and the final entry is five.

All of which you haven't asked for... but explains how my example using the day names actually works.

So now the bit you did ask for...

Python:
default day_count = 0

define days = ["Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
define final_day = 90

label start:

    "<<< START >>>"

label Sleeproom:

    $ day_count += 1

    if day_count > final_day:
        jump the_end

    $ today_name = days[day_count % 7]

    "So, today is [today_name] (Day [day_count])... What's the plan for today?"

    menu:
        "Sleep until tomorrow":
            jump Sleeproom

        "Go out":
            jump outside

label outside:

    "Hurrah! We saw sunlight briefly today for a change."
    "Time to go back to bed."

    jump Sleeproom

label the_end:

    "<<< THE END >>>"

    return
There you go... all 90 days in almost fewer lines of code than you original example of 3 days.

day_count keeps track of what day you are up to.
days and today_name show the name of the day of the week.
$ day_count += 1 increases the value of variable day_count by 1.

Not sure what you're planning for your label outside:, but you could conceiveably do somthing like:

Python:
label outside:

    if day_count == 1:
        jump outside_day_1

    if day_count == 2:
        jump outside_day_2

    if day_count == 3:
        jump outside_day_3

    # blah, blah, blah.

    "Tried to go outside on day [day_count] and there was nothing to do."
    jump Sleeproom

label outside_day_1:

    # do something clever here.
Honestly, there's probably some much cleverer way instead of a huge list of if statements. But for someone just starting out... I figure I've already made life hard enough for you by mentioning modulus and arrays.

Edit: Oh... and a bit of random trivia...
Whilst Sunday is the first day of the week in the USA, Canada, Australia and Japan - lots of other countries start the week on a Monday. Except most of the middle east... those start on a Saturday. Just in case your game is targeted at one specific region. And if you're looking to argue with someone... point out that the International Standards Organization say it's Monday (ISO 8601), even though the actual names come from Roman times when they named the days after the planets (Sun = Sunday, Moon = Monday, Saturn = Saturday - the rest don't translate into English very well).
 
Last edited:

h0932377128

New Member
Sep 25, 2019
13
3
I will try the code and will let you know soon. Thanks very much. Hopefully someone new to renpy without any knowledge of renpy, or python Can find this topic, which is interesting for them to apply to their games. Before I came here to ask, I searched a lot of documents but none of them I could understand. Too complicated. I thought I'd learn python first, which I really didn't really need. Because I really only tried one game. I am learning 3D graphics to make games, not related to coding at all. Thanks 79flavors :*****
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,979
16,236
Honestly, there's probably some much cleverer way instead of a huge list of if statements. But for someone just starting out... I figure I've already made life hard enough for you by mentioning modulus and arrays.
There's effectively, and it's not really more complicated than what you already talked about. But it's hidden in the depth of the documentation, between the "not documented" parts, and the "perhaps mostly related in some way" parts : The expression property.

It let you dynamically build the label name (or displayable, or something else, depending of the statement it apply to) according to the actual state of the game. Therefore, you can branch to anyone of the 90 outside labels with a single line.

Python:
label Sleeproom:

    $ day_count += 1

    if day_count > final_day:
        jump the_end

    $ today_name = days[day_count % 7]

    "So, today is [today_name] (Day [day_count])... What's the plan for today?"

    menu:
        "Sleep until tomorrow":
            jump Sleeproom

        "Go out":
            jump expression "outside_day_{}".format( day_count )

label outside_day_1:
    [...]
    jump Sleeproom

label outside_day_2:
    [...]
    jump Sleeproom

[...]

label outside_day_90:
    [...]
    jump the_end

Edit: Oh... and a bit of random trivia... [...] the rest don't translate into English very well).
What do you mean by "don't translate into English very well ?
Tuesday reflect the fact that it's the day of Mars, as accurately than "dimanche", the french for Sunday, reflect the fact it's the day of the "soleil" ;)

But, talking about this, there's a think really important when you make a game that will display a date, whatever which date. Always write the month with letters (Three first or all) and the year with its four digits. Between the US (MM/DD/YY), Japan (YY/MM/DD), most of Europe (DD/MM/YY), and the rest of the world, that use one of these, when they don't have their own format, doing otherwise will automatically confuse at least some players.
And here, going for a standardized format (like the YYYY-MM-DD ISO 8601 by example) will not necessarily help, since the player will not know from the start and assume that the author will use it's national format (while in the same time assuming the nationality of the said author).
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,258
What do you mean by "don't translate into English very well ?
Tuesday reflect the fact that it's the day of Mars, as accurately than "dimanche", the french for Sunday, reflect the fact it's the day of the "soleil" ;)
Maybe I should have said "[...] into English very well? ... at least as far as I know Engrish".
Oddly... The person who I would describe as knowing English and speaking English the best in my extended circle of friends... is Swiss.

As for French... My recollection is that I got 1% on my final French exam (for effectively getting my name right) at the age of 13. My teacher noted my written exam was practically 33% English, 33% German and 33% gibberish. I can't say I was too surprised.

As to using international standards for things like dates, times and formatting...
You don't have permission to view the spoiler content. Log in or register now.
 
Last edited:
  • Like
Reactions: h0932377128

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,979
16,236
Maybe I should have said "[...] into English very well? ... at least as far as I know Engrish".
Well, since we talk about this, in fact English day of the week reflect poorly the related "planet" because it was never really clear if Romans were referring to the "planet" or to the associated God. Therefore, like English is a made up language coming from more than a single culture, you've Saturday, Sunday and Monday that show the name of the "planet". While you've Tuesday, Wednesday, Thursday and Friday that, them, show the name of the Norse Gods equivalent to the Roman ones. Thursday being a reference to Thor, and the others... well I don't remember.


As for French... My recollection is that I got 1% on my final French exam (for effectively getting my name right) at the age of 13.
Hey, in my English classes I never goes further than what would be around 15% for you ; one time even my name was wrong, since the teacher insisted for us to use English first names :D
Yet look at me 30 years later.
 
  • Like
Reactions: h0932377128