Conditional Statements Aren't Working

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
NikMacPattyWak
Newbie
Posts: 10
Joined: Thu Sep 28, 2017 2:21 pm
Projects: Socializing Simulator
Github: nikkimacahon
Contact:

Conditional Statements Aren't Working

#1 Post by NikMacPattyWak »

I have a couple of questions that I want to remain hidden unless the character has accrued enough of a stat. When I want that to happen, I'd write out the code like this:

Code: Select all

susy "Do you even like pizza?" 
	menu:
	"Yes, of course I do!":
		jump pizza_yes
	"No, of course I don't!":
		jump pizza_no
	"How can you even talk about pizza at a time like this? Jim is dead!" if boldness >= 5:
		jump pizza_diversion
For some reason, regardless of how much "boldness" the character has, the option will pop up no matter what. I've also tried writing it like this:

Code: Select all

susy "Do you even like pizza?" 
	menu:
	"Yes, of course I do!" if boldness <= 5:
		jump pizza_yes
	"No, of course I don't!" if boldness <=5:
		jump pizza_no
	"How can you even talk about pizza at a time like this? Jim is dead!" if boldness >= 5:
		jump pizza_diversion

That hasn't worked either. Is there something I'm doing wrong?
-Nikki
nikkimacahon.com

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Conditional Statements Aren't Working

#2 Post by RicharDann »

The code itself seems fine, so the problem might be on how boldness is being defined and updated. Did you use default to initialize the variable? And how are you changing its value?
Quick example:

Code: Select all

default boldness = 0

label start:
    
    "Here's a menu to quickly test changes in the boldness variable."
    menu: 
        "Make me bold!":
            $ boldness += 3 # increase boldness by 3
            "Your current boldness level is [boldness]."
        "Make me bolder!":
            $ boldness += 5
            "Your current boldness level is [boldness]."

    susy "Do you even like pizza?" 
    
    menu:
        "Yes, of course I do!":
            jump pizza_yes
        "No, of course I don't!":
            jump pizza_no
        "How can you even talk about pizza at a time like this? Jim is dead!" if boldness >= 5:
            jump pizza_diversion

    return
The most important step is always the next one.

User avatar
NikMacPattyWak
Newbie
Posts: 10
Joined: Thu Sep 28, 2017 2:21 pm
Projects: Socializing Simulator
Github: nikkimacahon
Contact:

Re: Conditional Statements Aren't Working

#3 Post by NikMacPattyWak »

I'm defining my stats under the class resource. At the start of the game I set them all to zero, but for the purposes of the example I set boldness to 1 at the start. The way I've defined the class and increase/decrease stats looks like this.

Code: Select all

class resource:
        def __init__(self, starting_amount):
            self.level = starting_amount

        def __str__(self):
            return str(self.level)

        def dec(self):
            if self.level > 0:
                self.level = self.level - 1

        def inc(self,amount=1):
            self.level = self.level + amount

$boldness = resource(1)

label start:
        "Choose your destiny." 
        menu:
        	"Bravery.":
        		$boldness.inc(1)
        	"Cowardice.":
        		$boldness.dec(1)
-Nikki
nikkimacahon.com

User avatar
Enviel
Newbie
Posts: 11
Joined: Sat Apr 12, 2014 2:55 pm
Contact:

Re: Conditional Statements Aren't Working

#4 Post by Enviel »

With your resource class, conditional statements aren't using resource's level. Using

Code: Select all

"How can you even talk about pizza at a time like this? Jim is dead!" if boldness.level >= 5:
gives the expected result.

You probably need the specify how the comparison should be made if you want to directly use boldness instead of boldness.level here. For >=

Code: Select all

def __ge__(self, number):
    return self.level >= number
should do it, but other comparisons would need their own methods.

User avatar
NikMacPattyWak
Newbie
Posts: 10
Joined: Thu Sep 28, 2017 2:21 pm
Projects: Socializing Simulator
Github: nikkimacahon
Contact:

Re: Conditional Statements Aren't Working

#5 Post by NikMacPattyWak »

That worked! Thank you!
-Nikki
nikkimacahon.com

Post Reply

Who is online

Users browsing this forum: Google [Bot]