[FIXED]How make multiple "if" statements for choices (and other promblems)

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
GoldenMagician
Newbie
Posts: 19
Joined: Mon Mar 19, 2018 12:44 pm
Contact:

[FIXED]How make multiple "if" statements for choices (and other promblems)

#1 Post by GoldenMagician »

Hi everybody! I want to ask, according to title. For example:

Code: Select all

menu:
        "I'm sure!" if $ smth1 >= 0 and if $ energy_reserve >= 2 and if $ smth2 = False:
          if $ some_effect1 = true:
           "Yes, i'm sure!"
          elif $ some_effect2 = true:
            $ energy_reserve -= 3
            "Yes, i'm sure!"
          elif $ some_effect2 = true:
            $ energy_reserve -= 1
            "Yes, i'm sure!"
          else:
            $ energy_reserve -= 2
            "Yes, i'm sure!"
        "No...":
           "No..."
 

Code: Select all

$ energy_reserve = 5
$ smth1 = 0
$ smth2 = False
$ some_effect1 = True
$ some_effect2 = True
$ some_effect3 = False
Where is mistakes here? When I click Start, there is error... D: (sorry for maybe bad english)
p.s. I know. First choice ask 2 energy in reserve, but some_effect2 minus 3 energy. I will be grateful, if you help with this too
Last edited by GoldenMagician on Thu Mar 22, 2018 3:18 pm, edited 2 times in total.

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: How make multiple "if" statements for choices (and other promblems)

#2 Post by Alex »

Try

Code: Select all

menu:
        "I'm sure!" if smth1 >= 0 and energy_reserve >= 2 and smth2 == False:
          if some_effect1 == True:
The dollar sign is used at the beginning of a single-line python code.
Single equal sign is used for assigning, for comparison you need to use double equal sign.
Boolean values must start from capital letter.
You can set the values for you variables using default statement.

https://www.renpy.org/doc/html/index.html
https://www.renpy.org/doc/html/python.html
https://www.renpy.org/doc/html/python.h ... -statement

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: How make multiple "if" statements for choices (and other promblems)

#3 Post by Ocelot »

Code: Select all

# YOu need to use $ only to tell that next is Not a RenPy statement, but Python one.
# Conditions already expect Python expression, so you do not need it here
# The syntax is `if <condition>`; to join multiple conditions, use logical operators
"I'm sure!" if smth1 >= 0 and energy_reserve >= 2 and notsmth2:
    # `=` is "Make whatever is on left side to be thing on the right"
    # `==` is check for equality
    if some_effect1:
        "Yes, i'm sure!"
    # And it is True, not true
    elif some_effect2:
        $ energy_reserve -= 3
        "Yes, i'm sure!"
    # And you never need to compare to True (X == True ~ X)
    # Or False (X == False ~ not X)
    elif some_effect2:
        $ energy_reserve -= 1
        Yes, i'm sure!"
    else:
        $ energy_reserve -= 2
       "Yes, i'm sure!"
"No...":
    "No..."
< < insert Rick Cook quote here > >

GoldenMagician
Newbie
Posts: 19
Joined: Mon Mar 19, 2018 12:44 pm
Contact:

Re: How make multiple "if" statements for choices (and other promblems)

#4 Post by GoldenMagician »

Ocelot wrote: Mon Mar 19, 2018 2:54 pm

Code: Select all

# YOu need to use $ only to tell that next is Not a RenPy statement, but Python one.
# Conditions already expect Python expression, so you do not need it here
# The syntax is `if <condition>`; to join multiple conditions, use logical operators
"I'm sure!" if smth1 >= 0 and energy_reserve >= 2 and notsmth2:
    # `=` is "Make whatever is on left side to be thing on the right"
    # `==` is check for equality
    if some_effect1:
        "Yes, i'm sure!"
    # And it is True, not true
    elif some_effect2:
        $ energy_reserve -= 3
        "Yes, i'm sure!"
    # And you never need to compare to True (X == True ~ X)
    # Or False (X == False ~ not X)
    elif some_effect2:
        $ energy_reserve -= 1
        Yes, i'm sure!"
    else:
        $ energy_reserve -= 2
       "Yes, i'm sure!"
"No...":
    "No..."
Sorry, there is still problems. I'm write in the morning. I want to sleep...

GoldenMagician
Newbie
Posts: 19
Joined: Mon Mar 19, 2018 12:44 pm
Contact:

Re: How make multiple "if" statements for choices (and other promblems)

#5 Post by GoldenMagician »

Okay. This is code, where is minimum errors

Code: Select all

$ confident = False    
$ languor = True        
$ fearless = True       
$ uncertainty = False  
$ concentrated = False  
$ unfocused = False  
$ magic = 0               
$ strenght = 0            
$ eloquence = 0          
$ hacking = 0           
$ occult = 0             
$ dodge = 0             
$ interrogation = 0     
$ deception = 0        
$ mannerliness = 0     
$ psychology = 0        
$ trustful = 0           
$ energy_reserve = 5 

Code: Select all

label start:
menu:
    "I'm confident!" if $ trustful >= 0 and energy_reserve >= 2 and uncertainty == False:
        if fearless == true:
         "YES, I CONFIDENT!"
        elif languor == true:
         $ energy_reserve -= 3
         "YES, I CONFIDENT"
        elif confident == true:
         $ energy_reserve -= 1
         "YES, I CONFIDENT"
        else:
         $ energy_reserve -= 2
         "YES, I CONFIDENT"
    "Lol":
        "No..."
        
return
The only error is:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 29, in script
    menu:
SyntaxError: invalid syntax (game/script.rpy, line 30)

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 29, in script
    menu:
  File "C:\Users\MyName\Downloads (Yeah, Ren'Py still in this folder...)\renpy-6.99.14.1-sdk\renpy\ast.py", line 1504, in execute
    choice = renpy.exports.menu(choices, self.set)
  File "C:\Users\MyName\Downloads\renpy-6.99.14.1-sdk\renpy\exports.py", line 852, in menu
    if renpy.python.py_eval(condition) ]
  File "C:\Users\MyName\Downloads\renpy-6.99.14.1-sdk\renpy\python.py", line 1841, in py_eval
    code = py_compile(code, 'eval')
  File "C:\Users\MyName\Downloads\renpy-6.99.14.1-sdk\renpy\python.py", line 638, in py_compile
    raise e
SyntaxError: invalid syntax (game/script.rpy, line 30)

Windows-7-6.1.7601-SP1
Ren'Py 6.99.14.1.3218
MyGame
Tue Mar 20 07:01:51 2018

DannX
Regular
Posts: 99
Joined: Mon Mar 12, 2018 11:15 am
Contact:

Re: [STILL NOT FIXED]How make multiple "if" statements for choices (and other promblems)

#6 Post by DannX »

Please read carefully what other people tell you, they've pointed out you don't have to put the $ sign in if statements, just use the variable names. So it should be:

Code: Select all

"I'm confident!" if trustful >= 0 and energy_reserve >= 2 and uncertainty == False: 
Also, in the lines below, it should be True (with a capital T) instead of true, and also as previously stated, if you're checking if a condition is True, you don't need to add == True, it can be simplified like this:

Code: Select all

if fearless:
    "YES, I CONFIDENT!"

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: [STILL NOT FIXED]How make multiple "if" statements for choices (and other promblems)

#7 Post by trooper6 »

Programming is all about attention to detail. This includes capitalization, if there is a $ or not.

I will also note...that you should be declaring all of your variables using default.

So...

Code: Select all

default confident = False    
default languor = True        
default fearless = True       
default uncertainty = False  
default concentrated = False  
default unfocused = False  
default magic = 0               
default strenght = 0            
default eloquence = 0          
default hacking = 0           
default occult = 0             
default dodge = 0             
default interrogation = 0     
default deception = 0        
default mannerliness = 0     
default psychology = 0        
default trustful = 0           
default energy_reserve = 5 

label start:
    "Whatever happens in your game..."
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

GoldenMagician
Newbie
Posts: 19
Joined: Mon Mar 19, 2018 12:44 pm
Contact:

Re: [STILL NOT FIXED]How make multiple "if" statements for choices (and other promblems)

#8 Post by GoldenMagician »

trooper6 wrote: Tue Mar 20, 2018 3:44 pm Programming is all about attention to detail. This includes capitalization, if there is a $ or not.

I will also note...that you should be declaring all of your variables using default.

So...

Code: Select all

default confident = False    
default languor = True        
default fearless = True       
default uncertainty = False  
default concentrated = False  
default unfocused = False  
default magic = 0               
default strenght = 0            
default eloquence = 0          
default hacking = 0           
default occult = 0             
default dodge = 0             
default interrogation = 0     
default deception = 0        
default mannerliness = 0     
default psychology = 0        
default trustful = 0           
default energy_reserve = 5 

label start:
    "Whatever happens in your game..."
Pardon, but error still ocured. Maybe it helps, but for some reasons it didn't work. Same error

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: [STILL NOT FIXED]How make multiple "if" statements for choices (and other promblems)

#9 Post by trooper6 »

Post your current code.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

GoldenMagician
Newbie
Posts: 19
Joined: Mon Mar 19, 2018 12:44 pm
Contact:

Re: [STILL NOT FIXED]How make multiple "if" statements for choices (and other promblems)

#10 Post by GoldenMagician »

I make all variables with default.
Code, exactly after variables:

Code: Select all

label start:
menu:
    "I'm sure" if trustful >= 0 and energy_reserve >= 2 and  certainty == False:
        if fearless:
            "Yes, I'm sure!"
        elif languor:
            energy_reserve -= 3
            "Yes, I'm sure!"
        elif confident:
            energy_reserve -= 1
            "Yes, I'm sure!"
        else:
            energy_reserve -= 2
            "Yes, I'm sure!"
    "No...":
        "No..."
        
return
Error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 29, in script
    menu:
SyntaxError: invalid syntax (game/script.rpy, line 30)

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 29, in script
    menu:
  File "C:\Users\MyName\Downloads (Yeah, Ren'Py still in this folder...)\renpy-6.99.14.1-sdk\renpy\ast.py", line 1504, in execute
    choice = renpy.exports.menu(choices, self.set)
  File "C:\Users\MyName\Downloads\renpy-6.99.14.1-sdk\renpy\exports.py", line 852, in menu
    if renpy.python.py_eval(condition) ]
  File "C:\Users\MyName\Downloads\renpy-6.99.14.1-sdk\renpy\python.py", line 1841, in py_eval
    code = py_compile(code, 'eval')
  File "C:\Users\MyName\Downloads\renpy-6.99.14.1-sdk\renpy\python.py", line 638, in py_compile
    raise e
SyntaxError: invalid syntax (game/script.rpy, line 30)

Windows-7-6.1.7601-SP1
Ren'Py 6.99.14.1.3218
MyGame
Tue Mar 20 07:01:51 2018
If i add "default" to variables EXACTLY in code and before, error:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/script.rpy", line 34: expected '=' not found.
    default energy_reserve -== 3
                           ^

File "game/script.rpy", line 37: expected '=' not found.
    default energy_reserve -== 1
                           ^

File "game/script.rpy", line 40: expected '=' not found.
    default energy_reserve -== 2
                           ^

Ren'Py Version: Ren'Py 6.99.14.1.3218
Wed Mar 21 15:44:11 2018
And code:

Code: Select all

label start:
menu:
    "I'm sure" if default trustful >= 0 and default energy_reserve >= 2 and default certainty == False:
        if default fearless:
            "Yes, I'm sure!"
        elif default languor:
            default energy_reserve -= 3
            "Yes, I'm sure!"
        elif default confident:
            default energy_reserve -= 1
            "Yes, I'm sure!"
        else:
            default energy_reserve -= 2
            "Yes, I'm sure!"
    "No...":
        "No..."
        
return

DannX
Regular
Posts: 99
Joined: Mon Mar 12, 2018 11:15 am
Contact:

Re: [STILL NOT FIXED]How make multiple "if" statements for choices (and other promblems)

#11 Post by DannX »

default is a special word used in Renpy for creating variables, you only need to use it once, and it is only used to set variables to an initial, 'default' value, that means, not to add or substract, only to set. If you want to do those operations, in the script, that's when you use the $ sign.

Take a look at this code, it works, and it shows how everything in the script is supposed to be written and used.

Code: Select all

#First you create all your variables here with default
default confident = False    
default languor = True        
default fearless = False       
default uncertainty = False  
default concentrated = False  
default unfocused = False  
default magic = 0               
default strenght = 0            
default eloquence = 0          
default hacking = 0           
default occult = 0             
default dodge = 0             
default interrogation = 0     
default deception = 0        
default mannerliness = 0     
default psychology = 0        
default trustful = 0           
default energy_reserve = 5 

#The game starts here
label start:

#The game shows a menu
menu:
    "I'm sure" if trustful >= 0 and energy_reserve >= 2 and uncertainty == False: #Multiple conditions are checked
        if fearless:
            "Yes, I'm sure!"
        elif languor: 
            $ energy_reserve -= 3 #this substracts 3 to energy_reserve variable 
            "Yes, I'm sure!"
        elif confident:
            $ energy_reserve -= 1 #this substracts 1 
            "Yes, I'm sure!"
        else:
            $ energy_reserve -= 2 # 
            "Yes, I'm sure!"
    "No...":
        "No..."
return

GoldenMagician
Newbie
Posts: 19
Joined: Mon Mar 19, 2018 12:44 pm
Contact:

Re: [STILL NOT FIXED]How make multiple "if" statements for choices (and other promblems)

#12 Post by GoldenMagician »

DannX wrote: Thu Mar 22, 2018 10:14 am default is a special word used in Renpy for creating variables, you only need to use it once, and it is only used to set variables to an initial, 'default' value, that means, not to add or substract, only to set. If you want to do those operations, in the script, that's when you use the $ sign.

Take a look at this code, it works, and it shows how everything in the script is supposed to be written and used.

Code: Select all

#First you create all your variables here with default
default confident = False    
default languor = True        
default fearless = False       
default uncertainty = False  
default concentrated = False  
default unfocused = False  
default magic = 0               
default strenght = 0            
default eloquence = 0          
default hacking = 0           
default occult = 0             
default dodge = 0             
default interrogation = 0     
default deception = 0        
default mannerliness = 0     
default psychology = 0        
default trustful = 0           
default energy_reserve = 5 

#The game starts here
label start:

#The game shows a menu
menu:
    "I'm sure" if trustful >= 0 and energy_reserve >= 2 and uncertainty == False: #Multiple conditions are checked
        if fearless:
            "Yes, I'm sure!"
        elif languor: 
            $ energy_reserve -= 3 #this substracts 3 to energy_reserve variable 
            "Yes, I'm sure!"
        elif confident:
            $ energy_reserve -= 1 #this substracts 1 
            "Yes, I'm sure!"
        else:
            $ energy_reserve -= 2 # 
            "Yes, I'm sure!"
    "No...":
        "No..."
return
MY SAVIOR!!! IT'S FINALLY WORK!!! IT IS ALIVE!!!

Post Reply

Who is online

Users browsing this forum: Google [Bot]