Ren'Py Ok, one more Ren'py question

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,896
2,875
This is the last little bit of code that I need to fix for this VN adventure, then I should be good to go. Earlier on in the game there is a choice and I set variables:

Code:
menu:
     "What should I do?"

     "Look a little closer.":
        $ was_peeking = "true"
        jump peeking

     "Wait patiently in the living room.":
        $ was_peeking = "false"
        jump notpeeking
Later on I call on the variable was_peeking to shape other dialogue with a different character, to wit:

Code:
if was_peeking = true:
    jump was_peeking
else:
    jump was_not_peeking
I have looked this up multiple places and just can't see where I am goofing up on this code. Any assistance would be appreciated. I have tried putting quotes around "true" in the second case and not, but it does not seem to make a difference.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,969
16,222
I have looked this up multiple places and just can't see where I am goofing up on this code.
You really found nothing when you searched about Boolean value in Python and Ren'py ?

Code:
        $ was_peeking = True
Code:
        $ was_peeking = False
Code:
if was_peeking == True:
Edit: Oops, had missed the problem pointed by @Nottravis , fixed it.
 
  • Like
Reactions: Nottravis

Nottravis

Sci-fi Smutress
Donor
Game Developer
Jun 3, 2017
5,132
27,280
This is the last little bit of code that I need to fix for this VN adventure, then I should be good to go. Earlier on in the game there is a choice and I set variables:

Code:
menu:
     "What should I do?"

     "Look a little closer.":
        $ was_peeking = "true"
        jump peeking

     "Wait patiently in the living room.":
        $ was_peeking = "false"
        jump notpeeking
Later on I call on the variable was_peeking to shape other dialogue with a different character, to wit:

Code:
if was_peeking = true:
    jump was_peeking
else:
    jump was_not_peeking
I have looked this up multiple places and just can't see where I am goofing up on this code. Any assistance would be appreciated. I have tried putting quotes around "true" in the second case and not, but it does not seem to make a difference.
You'll kick yourself for this one. But don't worry I did exactly the same at one point. :)

In checking the variable try == instead of a single =. See if that works.
 

Quonix

Newbie
Donor
Game Developer
Nov 21, 2017
70
350
You set the variables wrong and you are also checking them wrong.
Code:
menu:
     "What should I do?"

     "Look a little closer.":
        $ was_peeking = True
        jump peeking

     "Wait patiently in the living room.":
        $ was_peeking = False
        jump notpeeking
By typing $ was_peeking = "true" or "false" you were setting was_peeking as a string, instead of as a boolean.

Code:
if was_peeking == True:
    jump was_peeking
else:
    jump was_not_peeking
Here you were also trying to set it as a boolean, instead of checking it, the difference lies in (1) = vs (2) == , = is for setting, == is for checking, although when checking if a boolean is true you can also just do:
Code:
if was_peeking:
    jump was_peeking
else:
    jump was_not_peeking
 
  • Like
Reactions: Nottravis

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,896
2,875
You really found nothing when you searched about Boolean value in Python and Ren'py ?
Fortunately I have made it very clear that I am a total NooB with Ren'py and Python (first project, loaded it less than a month ago), so I escape looking like an idiot. In order to find "Boolean value" in Python and Ren'py, I would have had to of known that it was a Boolean value I was looking for. Lesson learned.
 

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,896
2,875
You set the variables wrong and you are also checking them wrong.
Code:
menu:
     "What should I do?"

     "Look a little closer.":
        $ was_peeking = True
        jump peeking

     "Wait patiently in the living room.":
        $ was_peeking = False
        jump notpeeking
By typing $ was_peeking = "true" or "false" you were setting was_peeking as a string, instead of as a boolean.

Code:
if was_peeking == True:
    jump was_peeking
else:
    jump was_not_peeking
Here you were also trying to set it as a boolean, instead of checking it, the difference lies in (1) = vs (2) == , = is for setting, == is for checking, although when checking if a boolean is true you can also just do:
Code:
if was_peeking:
    jump was_peeking
else:
    jump was_not_peeking
Thanks for the clear explanation. Now I can see the difference between distinguishing something as a text variable as opposed to a Boolean value, and how to check a Boolean value. Thanks so much for your clear explanation.
 

Dogeek

Summertime Saga
Game Developer
Apr 20, 2018
74
510
Side note : you don't have to do if was_peeking == True. if evaluates any truthy value, which means that if was_peeking: is cleaner and more readable while still being syntactically correct.
 

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,896
2,875
Side note : you don't have to do if was_peeking == True. if evaluates any truthy value, which means that if was_peeking: is cleaner and more readable while still being syntactically correct.
Yes, you are right on that. I am literally in my first week of working with Python, so I am getting to know my way around it. Ideas like this will help me to write tighter code.