Ren'Py Question about indirect consequenzes

coffeeaddicted

Well-Known Member
Apr 13, 2021
1,831
1,497
I figured it out.

The syntax was wrong.

Though there is one question that remains. Based on the code i have and changed, what if a player love but then not loved the MC.
As of now, it checks for a greater number than 1. But that could change. How can i coded it so that it will check both conditions to make sure it will give the correct result.

Anyway, here is my code.

Code:
label choice_intro:
    "Am i staying with my husband?"

menu:

    "I will. I still love him.\n\nlove +1 [hint_1]":
        $ love += 1
        jump choice_intro01

    "I have no love anymore.\n\nlove -1 [hint_2]":
        $ love -= 1
        jump choice_intro01

label choice_intro01:

    if love is + 1:

            scene
            show erica_explaining07_agree
            with dissolve

            e "I truly love my husband. How could i leave him?\n\nlove +1 [hint_1]"
            n "(you have now {color=#00ffcc}[love]{/color} love point(s)"
            jump finish_intro

    else:

            scene
            show erica_explaining07_deny
            with dissolve

            e "I.. i really don't know. This is all so hard on me.\n\nlove -1 [hint_2]"
            n "(you have now {color=#00ffcc}[love]{/color} love point(s))"
            jump finish_intro


label finish_intro:

    stop music fadeout 2.0
    $ renpy.pause (2.0)

    play music "audio/Eyeliner.mp3" fadein 2.0

#blabla... dialog.

label choice_intro1:
    "Am i pretty?"

menu:

    "You are pretty.\n\nlove +1 [hint_1]":
        $ love += 1
        jump choice_intro2

    "You don't really look pretty.\n\nlove -1 [hint_2]":
        $ love -= 1
        jump choice_intro2

label choice_intro2:

    if love > 1:

            e "Thank you so much. You are such a charmer.\n\nlove +1 [hint_1]"
            n "(you have now {color=#00ffcc}[love]{/color} love point(s)"
            jump letsgo

    else:

            e "Aeh... thanks?\n\nlove -1 [hint_2]"
            n "(you have now {color=#00ffcc}[love]{/color} love point(s))"
            jump letsgo
 

moskyx

Forum Fanatic
Jun 17, 2019
4,248
14,068
You should really take a look at the Tutorial included in Ren'Py SDK. To check variables, you use > or < symbols (or == to check if the numeric value is an exact one)
 
  • Like
Reactions: coffeeaddicted

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,260
I see two problems.

You're using $ love = +1. That will set the value of love to a value of +1 (i.e. 1).

In older languages, you'd normally do $ love = love + 1 (set love to be the value of love plus 1).
With python, it has a shortcut way of typing it... $ love += 1. I think this is what you intended. Tiny change in where the plus sign is put... but programming languages are funny that way.

See :

Secondly, you're checking for if love is +1:.

Use of is is usually restricted to testing if two objects are the same type. But it works here anyway... sort of.
Your code is basically doing if love == 1: (that is, if the value of love "equal to" 1).

Be very careful here. if love = 1: is NOT a check for comparing a variable with a value, since = is used to set a variable to a value in python (hence the ==).

The same link above will explain all the different type of check (for example != being "not equal to").
For a more RenPy introduction, you could read my Introduction to Variables post from a couple of years ago.

You can't really check if love == 2: in circumstances like this... because it doesn't tell you what the player picked from the choices menu. If you have three checks, all of which do $ love += 1 if you pick "Yes" - What if the player picks "Yes/Yes/No" or "No/Yes/Yes"... both will have a value of 2 - but you can't figure out what the player picked from the 3rd choice based on that.

Personally, I'd code it as:

Python:
    menu:
        "You are pretty.\n\nlove +1 [hint_1]":
            e "Thank you so much. You are such a charmer."
            n "(you have now {color=#00ffcc}[love]{/color} love point(s)"
            $ love = +1

        "You don't really look pretty.\n\nlove -1 [hint_2]":
            e "Aeh... thanks?"
            n "(you have now {color=#00ffcc}[love]{/love} love point(s))"

Although, more similar to your existing code could be:

Python:
    menu:

        "You are pretty.\n\nlove +1 [hint_1]":
            jump choice_intro2_choice_1

        "You don't really look pretty.\n\nlove -1 [hint_2]":
            jump choice_intro2_choice_2


label choice_intro2_choice_1:

    e "Thank you so much. You are such a charmer."
    n "(you have now {color=#00ffcc}[love]{/color} love point(s)"

    $ love = +1
   
    jump choice_intro2_continue

   
label choice_intro2_choice_2:

    e "Aeh... thanks?\n\nlove -1 [hint_2]"
    n "(you have now {color=#00ffcc}[love]{/love} love point(s))"
    jump choice_intro2_continue


label choice_intro2_continue:

    # game continues.

or maybe even:

Python:
menu:

    "You are pretty.\n\nlove +1 [hint_1]":
        $ choice = 1

    "You don't really look pretty.\n\nlove -1 [hint_2]":
        $ choice = 2

    if choice == 1:
        e "Thank you so much. You are such a charmer."
        n "(you have now {color=#00ffcc}[love]{/color} love point(s)"
        $ love = +1
   
    if choice == 2:
        e "Aeh... thanks?\n\nlove -1 [hint_2]"
        n "(you have now {color=#00ffcc}[love]{/love} love point(s))"

    # game continues.

Now you're other potential pitfalls...

You're not indenting quite right yet. Almost, but not right.

menu: needs to be indented 4 more spaces. Though more accurate would be say that statements after the label: need to be indented by 4 spaces. RenPy will ignore the rules sometimes, which is why it still works - but indenting is important in python (and therefore RenPy)... so better you avoid bad habits from the start.

Next... if you don't need to change the value of variable... simply don't. No need to do stuff like $ love += 0 for example.

However, sometimes this leaves you with if or menu: statements that are effectively "do nothing".

RenPy has you covered here, where it as command called pass, which is the same as "do nothing".

So using the example of earlier in a different way:

Python:
    menu:

        "You are pretty":
            $ love += 1

        "You don't really look pretty":
            pass

You only need to use put pass anywhere when the line would empty otherwise, and the command needs to do something.

EDIT: Finally...

You're using a character n to show non-character related text. For example n "(you have [love] love point(s)"

RenPy already has a mechanism for this... you simply DON'T use a Character() object on the line of dialogue.

So....

Python:
    a "This is spoken by the character A."
    b "This is spoken by the character B."
    "This is spoken by a blank/unknown character".

In actuality, it's using a character called narrator. Any time dialogue is included within the script without a character speaking it... it is spoken by narrator.

You can even override it if you like... For example, I like to change the default color of narration to a light yellow instead of white using...

Python:
define narrator = Character("", what_color="#FFFF66")
See : https://f95zone.to/threads/write-the-text-always-in-italic.122138/post-8446564 for an over the top version of this.
 
Last edited:
  • Like
Reactions: coffeeaddicted

moskyx

Forum Fanatic
Jun 17, 2019
4,248
14,068
I see two problems.

You're using $ love = +1. That will set the value of love to a value of +1 (i.e. 1).

In older languages, you'd normally do $ love = love + 1 (set love to be the value of love plus 1).
With python, it has a shortcut way of typing it... $ love += 1. I think this is what you intended. Tiny change in where the plus sign is put... but programming languages are funny that way.

See :

Secondly, you're checking for if love is +1:.

Use of is is usually restricted to testing if two objects are the same type. But it works here anyway... sort of.
Your code is basically doing if love == 1: (that is, if the value of love "equal to" 1).

Be very careful here. if love = 1: is NOT a check for comparing a variable with a value, since = is used to set a variable to a value in python (hence the ==).

The same link above will explain all the different type of check (for example != being "not equal to").
For a more RenPy introduction, you could read my Introduction to Variables post from a couple of years ago.

You can't really check if love == 2: in circumstances like this... because it doesn't tell you what the player picked from the choices menu. If you have three checks, all of which do $ love += 1 if you pick "Yes" - What if the player picks "Yes/Yes/No" or "No/Yes/Yes"... both will have a value of 2 - but you can't figure out what the player picked from the 3rd choice based on that.

Personally, I'd code it as:

Python:
    menu:
        "You are pretty.\n\nlove +1 [hint_1]":
            e "Thank you so much. You are such a charmer."
            n "(you have now {color=#00ffcc}[love]{/color} love point(s)"
            $ love = +1

        "You don't really look pretty.\n\nlove -1 [hint_2]":
            e "Aeh... thanks?"
            n "(you have now {color=#00ffcc}[love]{/love} love point(s))"

Although, more similar to your existing code could be:

Python:
    menu:

        "You are pretty.\n\nlove +1 [hint_1]":
            jump choice_intro2_choice_1

        "You don't really look pretty.\n\nlove -1 [hint_2]":
            jump choice_intro2_choice_2


label choice_intro2_choice_1:

    e "Thank you so much. You are such a charmer."
    n "(you have now {color=#00ffcc}[love]{/color} love point(s)"

    $ love = +1
  
    jump choice_intro2_continue

  
label choice_intro2_choice_2:

    e "Aeh... thanks?\n\nlove -1 [hint_2]"
    n "(you have now {color=#00ffcc}[love]{/love} love point(s))"
    jump choice_intro2_continue


label choice_intro2_continue:

    # game continues.

or maybe even:

Python:
menu:

    "You are pretty.\n\nlove +1 [hint_1]":
        $ choice = 1

    "You don't really look pretty.\n\nlove -1 [hint_2]":
        $ choice = 2

    if choice == 1:
        e "Thank you so much. You are such a charmer."
        n "(you have now {color=#00ffcc}[love]{/color} love point(s)"
        $ love = +1
  
    if choice == 2:
        e "Aeh... thanks?\n\nlove -1 [hint_2]"
        n "(you have now {color=#00ffcc}[love]{/love} love point(s))"

    # game continues.

Now you're other potential pitfalls...

You're not indenting quite right yet. Almost, but not right.

menu: needs to be indented 4 more spaces. Though more accurate would be say that statements after the label: need to be indented by 4 spaces. RenPy will ignore the rules sometimes, which is why it still works - but indenting is important in python (and therefore RenPy)... so better you avoid bad habits from the start.

Next... if you don't need to change the value of variable... simply don't. No need to do stuff like $ love += 0 for example.

However, sometimes this leaves you with if or menu: statements that are effectively "do nothing".

RenPy has you covered here, where it as command called pass, which is the same as "do nothing".

So using the example of earlier in a different way:

Python:
    menu:

        "You are pretty":
            $ love += 1

        "You don't really look pretty":
            pass

You only need to use put pass anywhere when the line would empty otherwise, and the command needs to do something.
I'd say that he should add the points before showing the text. Something like this:

Python:
    menu:

        "You are pretty.\n\nlove +1 [hint_1]":
            jump choice_intro2_choice_1

        "You don't really look pretty.\n\nlove -1 [hint_2]":
            jump choice_intro2_choice_2


label choice_intro2_choice_1:

    e "Thank you so much. You are such a charmer."
    $ love += 1 #This is the change, so the love variable "quoted" in the next line will show the updated value
    n "(you have now {color=#00ffcc}[love]{/color} love point(s)"

   
  
    jump choice_intro2_continue

  
label choice_intro2_choice_2:

    e "Aeh... thanks?\n\nlove -1 [hint_2]"
    n "(you have now {color=#00ffcc}[love]{/love} love point(s))"
    jump choice_intro2_continue


label choice_intro2_continue:

    # game continues.
 

coffeeaddicted

Well-Known Member
Apr 13, 2021
1,831
1,497
You should really take a look at the Tutorial included in Ren'Py SDK. To check variables, you use > or < symbols (or == to check if the numeric value is an exact one)
I think that is really needed.
As of now i just check if love is given.
The question i am asking myself is this.
Should the selection take precedent or the > variable?
I think that i should reflect the choice over the value. So player selects choice, this is what should be shown with score.
Back to the drawing board. :)
 

coffeeaddicted

Well-Known Member
Apr 13, 2021
1,831
1,497
I see two problems.

You're using $ love = +1. That will set the value of love to a value of +1 (i.e. 1).

In older languages, you'd normally do $ love = love + 1 (set love to be the value of love plus 1).
With python, it has a shortcut way of typing it... $ love += 1. I think this is what you intended. Tiny change in where the plus sign is put... but programming languages are funny that way.

See :

Secondly, you're checking for if love is +1:.

Use of is is usually restricted to testing if two objects are the same type. But it works here anyway... sort of.
Your code is basically doing if love == 1: (that is, if the value of love "equal to" 1).

Be very careful here. if love = 1: is NOT a check for comparing a variable with a value, since = is used to set a variable to a value in python (hence the ==).

The same link above will explain all the different type of check (for example != being "not equal to").
For a more RenPy introduction, you could read my Introduction to Variables post from a couple of years ago.

You can't really check if love == 2: in circumstances like this... because it doesn't tell you what the player picked from the choices menu. If you have three checks, all of which do $ love += 1 if you pick "Yes" - What if the player picks "Yes/Yes/No" or "No/Yes/Yes"... both will have a value of 2 - but you can't figure out what the player picked from the 3rd choice based on that.

Personally, I'd code it as:

Python:
    menu:
        "You are pretty.\n\nlove +1 [hint_1]":
            e "Thank you so much. You are such a charmer."
            n "(you have now {color=#00ffcc}[love]{/color} love point(s)"
            $ love = +1

        "You don't really look pretty.\n\nlove -1 [hint_2]":
            e "Aeh... thanks?"
            n "(you have now {color=#00ffcc}[love]{/love} love point(s))"

Although, more similar to your existing code could be:

Python:
    menu:

        "You are pretty.\n\nlove +1 [hint_1]":
            jump choice_intro2_choice_1

        "You don't really look pretty.\n\nlove -1 [hint_2]":
            jump choice_intro2_choice_2


label choice_intro2_choice_1:

    e "Thank you so much. You are such a charmer."
    n "(you have now {color=#00ffcc}[love]{/color} love point(s)"

    $ love = +1
   
    jump choice_intro2_continue

   
label choice_intro2_choice_2:

    e "Aeh... thanks?\n\nlove -1 [hint_2]"
    n "(you have now {color=#00ffcc}[love]{/love} love point(s))"
    jump choice_intro2_continue


label choice_intro2_continue:

    # game continues.

or maybe even:

Python:
menu:

    "You are pretty.\n\nlove +1 [hint_1]":
        $ choice = 1

    "You don't really look pretty.\n\nlove -1 [hint_2]":
        $ choice = 2

    if choice == 1:
        e "Thank you so much. You are such a charmer."
        n "(you have now {color=#00ffcc}[love]{/color} love point(s)"
        $ love = +1
   
    if choice == 2:
        e "Aeh... thanks?\n\nlove -1 [hint_2]"
        n "(you have now {color=#00ffcc}[love]{/love} love point(s))"

    # game continues.

Now you're other potential pitfalls...

You're not indenting quite right yet. Almost, but not right.

menu: needs to be indented 4 more spaces. Though more accurate would be say that statements after the label: need to be indented by 4 spaces. RenPy will ignore the rules sometimes, which is why it still works - but indenting is important in python (and therefore RenPy)... so better you avoid bad habits from the start.

Next... if you don't need to change the value of variable... simply don't. No need to do stuff like $ love += 0 for example.

However, sometimes this leaves you with if or menu: statements that are effectively "do nothing".

RenPy has you covered here, where it as command called pass, which is the same as "do nothing".

So using the example of earlier in a different way:

Python:
    menu:

        "You are pretty":
            $ love += 1

        "You don't really look pretty":
            pass

You only need to use put pass anywhere when the line would empty otherwise, and the command needs to do something.
Learning is sometimes a roller coaster but you are absolutely correct.

1) i think i should forget about the if player selected yes to get +1 and go for the choice. After all, this will make sure that whatever the player selects, will be shown.
So i like the 3th example.

2) the syntax, that was a little research. At one point i cam across a blog where it was shown. It makes sense now but i assumed that the $ love = +1 would be the correct. I think that's how it was on RenPy.

3) indentation. Oh boy, i am using Atom at the moment and it has the option to move the line in or out. Even automatically.
But i think i should follow your advise here.

I am really a bloody beginner in programming. Though what i am doing isn't probably complicated but to think abstract is something i am not terribly great in.
So it will take me some time to get that right. Especially for someone old like me.
I am trying to be as structural and correct as possible. But i realized that RenPy does ignore things if they aren't setup right.

So thank you for pointing all this out. This helps a lot.

It is a great experience so far, even with the problems that come.
 

coffeeaddicted

Well-Known Member
Apr 13, 2021
1,831
1,497
I'd say that he should add the points before showing the text. Something like this:

Python:
    menu:

        "You are pretty.\n\nlove +1 [hint_1]":
            jump choice_intro2_choice_1

        "You don't really look pretty.\n\nlove -1 [hint_2]":
            jump choice_intro2_choice_2


label choice_intro2_choice_1:

    e "Thank you so much. You are such a charmer."
    $ love += 1 #This is the change, so the love variable "quoted" in the next line will show the updated value
    n "(you have now {color=#00ffcc}[love]{/color} love point(s)"

  
 
    jump choice_intro2_continue

 
label choice_intro2_choice_2:

    e "Aeh... thanks?\n\nlove -1 [hint_2]"
    n "(you have now {color=#00ffcc}[love]{/love} love point(s))"
    jump choice_intro2_continue


label choice_intro2_continue:

    # game continues.
Yes, i did that. Seems that it won't be shown when you do it after.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,260
Just to point out I did an edit to the post to talk about your character n too.

And yes, moskyx is correct that I've put the $ love += 1 in the wrong place. I tend to not update variables until the last second. Just a habit. But in this case, it overlooks that the game shows the value to the player before then.
 
  • Like
Reactions: coffeeaddicted

coffeeaddicted

Well-Known Member
Apr 13, 2021
1,831
1,497
Just to point out I did an edit to the post to talk about your character n too.

And yes, moskyx is correct that I've put the $ love += 1 in the wrong place. I tend to not update variables until the last second. Just a habit. But in this case, it overlooks that the game shows the value to the player before then.
Oh.

I did not realize this.
Thank you so much. Again, something learned. I thought, well i just let the narrator talk.
I will change that as well. :)