Multiple Conditional Statements and Variables

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
marauderspirit
Newbie
Posts: 19
Joined: Thu Sep 25, 2014 5:45 am
Completed: Act of Mercy
Projects: Act of Vengeance, Vice/Arcana
Organization: Zircona Works
Tumblr: zirconaworks
Location: Neptune
Contact:

Multiple Conditional Statements and Variables

#1 Post by marauderspirit »

Hello people! I am a complete novice, so bear with me.

I am trying to build a section of my game which begins in a dark room. The player can turn on the lights in another room, and thereby gain access to the lit version of the room. I also have a additional variable which sets the room to false, if not visited, and true, if visited, so that if the player returns to the room after they have visited it once, they get a new scene. The conditions for the lights work perfectly, however, when I add the third conditional, which is the visited variable, then I find that the game is just not accepting it. It does not seem to take. I have wondered if for this section I ought to use a point system, but that seems very complicated for something that to me seems small. I have also tried used the elif and else statements, to no avail. I will paste below my code.

Code: Select all

label boxoffice:
    
   
    if lights == "off":
        
            scene bg box office unlit
            with fade
    
            "It's too dark to see in here. I need to turn on the lights."
        
            $ renpy.pause()

            jump lobbymenu
    
    if lights == "on":
        
            scene bg box office lit
            with fade
        
            "The lights are on."

            $ elementstones += 1
            
            $ boxoffice == "true"
        
            $ renpy.pause()

            jump lobbymenu
        
    if boxoffice == "true":
        
            scene bg box office nostone
            with fade
        
            "It works!"
        
            $ renpy.pause()

            jump lobbymenu

For the record, the variables set at the beginning of the game are as follows:

Code: Select all

label start:

    $ auditoriumdoors = "closed"
    
    $ elementstones = 0
    
    $ lights = "off"
    
    $ storeroom = "false"
    
    $ boxoffice = "false"
    
    $ salon = "false"

Anima
Veteran
Posts: 448
Joined: Wed Nov 18, 2009 11:17 am
Completed: Loren
Projects: PS2
Location: Germany
Contact:

Re: Multiple Conditional Statements and Variables

#2 Post by Anima »

The lights variable is probably either "on" or "off". So you never reach the third if statement since you jump to lobbymenu in either of the first two blocks.
You need to put the jump after the if statements.
Avatar created with this deviation by Crysa
Currently working on:
  • Winterwolves "Planet Stronghold 2" - RPG Framework: Phase III

User avatar
marauderspirit
Newbie
Posts: 19
Joined: Thu Sep 25, 2014 5:45 am
Completed: Act of Mercy
Projects: Act of Vengeance, Vice/Arcana
Organization: Zircona Works
Tumblr: zirconaworks
Location: Neptune
Contact:

Re: Multiple Conditional Statements and Variables

#3 Post by marauderspirit »

Thanks for the swift reply!

The menu for the lobby is essentially static, the player is able to re-visit areas many times using this hub zone. When you say that the jump option should be after the 'if' statements, do you mean at the end of the entire label block? Could you please elaborate a little bit on your answer, I'm afraid I'm having difficulty following you.

Many thanks

EDIT:

I tried popping the jump statement at the end of the block, but although I received no errors, I'm afraid the third conditional is still not manifesting. :(

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

Re: Multiple Conditional Statements and Variables

#4 Post by Alex »

The third option would never be accessible, 'cause your "lights" variable can have one of two values (on / off) and you make the game to jump to different places in both cases. Try to set "lights" variable to another value before "boxoffice" lable.

User avatar
marauderspirit
Newbie
Posts: 19
Joined: Thu Sep 25, 2014 5:45 am
Completed: Act of Mercy
Projects: Act of Vengeance, Vice/Arcana
Organization: Zircona Works
Tumblr: zirconaworks
Location: Neptune
Contact:

Re: Multiple Conditional Statements and Variables

#5 Post by marauderspirit »

I'm sorry, I'm just not following either of you. I apologise, I'm a real noob! Are you saying that a single label can only contain one variable (set to either, essentially, true or false)? How I envisioned it was that the player visited the box office, saw the lights were off, went to another room, at which point a variable sets the lights on. When the player returns, the lights are now on, and what I want is for another variable to activate which says the room has been visited. Is it possible then to have a variable with multiple conditions? I'm very confused...

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

Re: Multiple Conditional Statements and Variables

#6 Post by Alex »

Well, you can use as many variables as you need for your game logic. The way program work is that it runs your code lines in order you wrote them in your script, so at first it will check if the "lights" are off and will jump to "lobbymenu" if so, and if it's not so, it will check if "lights" are on... You see, if you have only two states for "lights" you need to add another condition to reach the access to the third option. Try

Code: Select all

label boxoffice:
    
   
    if lights == "off":
        
            scene bg box office unlit
            with fade
    
            "It's too dark to see in here. I need to turn on the lights."
        
            $ renpy.pause()

            jump lobbymenu
    
    if lights == "on" and boxoffice == "false":    <=== this part of code will be executed only if both conditions are met
        
            scene bg box office lit
            with fade
        
            "The lights are on."

            $ elementstones += 1
            
            $ boxoffice == "true"
        
            $ renpy.pause()

            jump lobbymenu
        
    if boxoffice == "true":
        
            scene bg box office nostone
            with fade
        
            "It works!"
        
            $ renpy.pause()

            jump lobbymenu

Anima
Veteran
Posts: 448
Joined: Wed Nov 18, 2009 11:17 am
Completed: Loren
Projects: PS2
Location: Germany
Contact:

Re: Multiple Conditional Statements and Variables

#7 Post by Anima »

The problem is this line:

Code: Select all

$ boxoffice == "true"
That's an equality check, an assignment is done with a single =:

Code: Select all

$ boxoffice = "true"
In addition you can use python truth values for these instead of strings.
The full corrected code would be:

Code: Select all

label boxoffice:
    
   
    if not lights:
        
            scene bg box office unlit
            with fade
    
            "It's too dark to see in here. I need to turn on the lights."
        
            $ renpy.pause()
    
    else:
        
            scene bg box office lit
            with fade
        
            "The lights are on."

            $ elementstones += 1
            
            $ boxoffice = True
        
            $ renpy.pause()
        
    if boxoffice:
        
            scene bg box office nostone
            with fade
        
            "It works!"
        
            $ renpy.pause()

    jump lobbymenu

Code: Select all

label start:

    $ auditoriumdoors = "closed"
    
    $ elementstones = 0
    
    $ lights = False
    
    $ storeroom = False
    
    $ boxoffice = False
    
    $ salon = False
And of course you'd need to change the checks for the variables throughout the script like in the example.
Avatar created with this deviation by Crysa
Currently working on:
  • Winterwolves "Planet Stronghold 2" - RPG Framework: Phase III

User avatar
marauderspirit
Newbie
Posts: 19
Joined: Thu Sep 25, 2014 5:45 am
Completed: Act of Mercy
Projects: Act of Vengeance, Vice/Arcana
Organization: Zircona Works
Tumblr: zirconaworks
Location: Neptune
Contact:

Re: Multiple Conditional Statements and Variables

#8 Post by marauderspirit »

It works!

I realised I made a mistake in the syntax as Anima pointed out. In addition, Alex's solution also got me there.

In the end, the code is thus:

Code: Select all

label boxoffice:
    
   
    if lights == "off":
        
            scene bg box office unlit
            with fade
    
            "It's too dark to see in here. I need to turn on the lights."
        
            $ renpy.pause()
            jump lobbymenu

    
    if lights == "on" and boxoffice == "false":
        
            scene bg box office lit
            with fade
        
            "The lights are on."

            $ elementstones += 1
            
            $ boxoffice = "true"
        
            $ renpy.pause()
            jump lobbymenu


        
    if boxoffice == "true":
        
            scene bg box office nostone
            with fade
        
            "It works!"
        
            $ renpy.pause()

            jump lobbymenu
Thanks everyone, you guys kick ass!

Post Reply

Who is online

Users browsing this forum: IrisColt