[SOLVED] If Statement and Variables Not 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
codenewbie
Newbie
Posts: 18
Joined: Tue Apr 17, 2018 11:21 pm

[SOLVED] If Statement and Variables Not Working

#1 Post by codenewbie »

Hello! I'm new to both Ren'Py and coding. I'm trying to work with an if statement and variables. I want the player to go through all three menu choices before being able to move on with the game. So far, I have the following code, but the game just loops the menu over and over again.

Code: Select all

    define memCount = 0 #when memCount = total # of mems in the room, can move on

    scene bg dining room
    if memCount == 3:
        "all three memories collected"
        return
    else:
        menu DiningRoom:
            with Dissolve(1.0)
            "Fish":
                jump fish
            "Cat Painting":
                jump catpainting
            "Plant":
                jump plant

        label fish:
            $ memCount += 1 #increment memory count
            "fish"
            jump DiningRoom

        label catpainting:
            $ memCount += 1 #increment memory count
            "cat painting"
            jump DiningRoom

        label plant:
            $ memCount += 1 #increment memory count
            "plant"
            jump DiningRoom
Thank you!
Last edited by codenewbie on Wed Apr 18, 2018 12:21 pm, edited 1 time in total.

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: If Statement and Variables Not Working

#2 Post by trooper6 »

Put this in a new project and check it out.

Code: Select all

# Define varbles
default hasFish = False
default hasCat = False
default hasPlant = False

# The game starts here.

label start():
    "Your game has started."
    
    menu diningRoom:
        "Think on memories?"
        "Fish" if not hasFish:
            jump fish
        "Cat Painting" if not hasCat:
            jump catpainting
        "Plant" if not hasPlant:
            jump plant
        "All three memories collected. Continue on." if hasFish and hasCat and hasPlant:
            jump theNextScene

    return

label fish():
    $hasFish = True
    "Fish"
    jump diningRoom

label catpainting():
    $hasCat = True
    "cat painting"
    jump diningRoom

label plant():
    $hasPlant = True
    "plant"
    jump diningRoom

label theNextScene():
    "The game continues on."
    return

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

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

Re: If Statement and Variables Not Working

#3 Post by Ocelot »

In addition to trooper6 answer: Source of your problem is your jumps aftermenu item labels. You are jumping directly to menu, completely skipping check for memory.
< < insert Rick Cook quote here > >

codenewbie
Newbie
Posts: 18
Joined: Tue Apr 17, 2018 11:21 pm

Re: If Statement and Variables Not Working

#4 Post by codenewbie »

I see! Thank you both for your help! :D

Post Reply

Who is online

Users browsing this forum: Ocelot, snotwurm