Dealing with Multiple (&&) Statements

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
TennisHero
Newbie
Posts: 13
Joined: Thu Jan 21, 2016 5:32 pm
Deviantart: TennisHero
Contact:

Dealing with Multiple (&&) Statements

#1 Post by TennisHero » Thu Aug 25, 2016 6:51 pm

I'm writing this scene in my story where the main character has to remember a restaurant order and then input the correct commands. There is a 4x4 grid of the options listed, and all four of these must be correct in order to progress. So for example, if the order was "Steak bowl with white rice", all four of these variables would have to match up.

Code: Select all

protein = "steak" 
starch = "white"
entree = "bowl"
topping = "none"


The game crashes when it check the variables in label food. What do I need to change so that it works the way I want it to?

Code: Select all

screen order:
    
    tag menu
    modal True

    default protein = None
    default starch  = None
    default entree  = None
    default topping = None

    frame:
        style_group "schedule"       
        xalign .5
        yalign .40
       
        #This controls vertical spacing
        has vbox spacing 20

        label "Menu"

        grid 4 5:
            transpose True
           
            label "Protein"
            textbutton "Steak" action SetScreenVariable("protein", "steak")
            textbutton "Chicken" action SetScreenVariable("protein", "chicken")
            textbutton "BBQ Pork" action SetScreenVariable("protein", "pork")
            textbutton "Tofu" action SetScreenVariable("protein", "tofu")
           
            label "Rice/Beans"
            textbutton "White Rice" action SetScreenVariable("starch", "white")
            textbutton "Brown Rice" action SetScreenVariable("starch", "brown")
            textbutton "Black Beans" action SetScreenVariable("starch", "black")
            textbutton "Pinto Beans" action SetScreenVariable("starch", "pinto")
           
            label "Entree"
            textbutton "Bowl" action SetScreenVariable("entree", "bowl")
            textbutton "Wrap" action SetScreenVariable("entree", "wrap")
            textbutton "Taco" action SetScreenVariable("entree", "taco")
            textbutton "Salad" action SetScreenVariable("entree", "salad")
           
            label "Topping"
            textbutton "Sour Cream" action SetScreenVariable("topping", "sourcream")
            textbutton "Chili" action SetScreenVariable("topping", "chili")
            textbutton "Guacamole" action SetScreenVariable("topping", "guacamole")
            textbutton "None" action SetScreenVariable("topping", "none")

        hbox:
            xalign 0.5
            textbutton "Done" action [Hide("menu2"), Jump("food")]
            textbutton "Cancel" action Hide("menu")   
 

init python:
    style.schedule_button.xminimum = 180
    style.schedule_label.xalign = .5
    
    
label food:    
    #Check if all four variables match the correct order

    if (protein = "tofu" and starch = "brown" and entree = "bowl" and topping = "guacamole"):
        "Good job!"

    if (protein = "chicken" and starch = "pinto" and entree = "wrap" and topping = "none"):
        "Good job!"
 
    else:
        "That doesn't sound right."  

User avatar
papiersam
Veteran
Posts: 231
Joined: Fri Aug 12, 2016 2:24 pm
Completed: Gem Hunt Beta, 1/Probably, Animunch
Projects: The Panda Who Dreamed
Contact:

Re: Dealing with Multiple (&&) Statements

#2 Post by papiersam » Thu Aug 25, 2016 7:05 pm

You're casting, not comparing:

Code: Select all

  if (protein = "tofu" and starch = "brown" and entree = "bowl" and topping = "guacamole"):
What you're doing here is setting protein to tofu, setting starch to brown, and so forth. If you want to compare, use '=='

Code: Select all

  if (protein == "tofu" and starch == "brown" and entree == "bowl" and topping == "guacamole"):
Side note: what I've noticed in Renpy is that it actually throws an error in this case. In my experience, C++ and Java just evaluate the statement after it casts it, and it usually evaluates to true. It's actually handy to be given the error message.

Hope this helps.

Edit: Also, if it causes an error afterwards, I think you have to define:

Code: Select all

    default protein = None
    default starch  = None
    default entree  = None
    default topping = None
outside of the screen. But that is only if it does cause an error.

TennisHero
Newbie
Posts: 13
Joined: Thu Jan 21, 2016 5:32 pm
Deviantart: TennisHero
Contact:

Re: Dealing with Multiple (&&) Statements

#3 Post by TennisHero » Thu Aug 25, 2016 7:19 pm

I've made the changes and it helped solve my error problem. But now when I input the right command, it's telling me that it's incorrect.

In this case, "tofu, brown rice, bowl, guacamole" reads "That doesn't sound right."

Code: Select all

label food:    
    if (protein == "tofu" and starch == "brown" and entree == "bowl" and topping == "guacamole"):
        "Good job!"
                        
    else:
        "That doesn't sound right."  
Last edited by TennisHero on Thu Aug 25, 2016 7:24 pm, edited 1 time in total.

User avatar
papiersam
Veteran
Posts: 231
Joined: Fri Aug 12, 2016 2:24 pm
Completed: Gem Hunt Beta, 1/Probably, Animunch
Projects: The Panda Who Dreamed
Contact:

Re: Dealing with Multiple (&&) Statements

#4 Post by papiersam » Thu Aug 25, 2016 7:23 pm


TennisHero
Newbie
Posts: 13
Joined: Thu Jan 21, 2016 5:32 pm
Deviantart: TennisHero
Contact:

Re: Dealing with Multiple (&&) Statements

#5 Post by TennisHero » Thu Aug 25, 2016 7:26 pm

It worked. Thank You!

Post Reply

Who is online

Users browsing this forum: Google [Bot]