Python "if statements" 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
Leehua
Newbie
Posts: 4
Joined: Thu Jun 14, 2018 2:41 pm
Deviantart: tsaileehua
Contact:

Python "if statements" not working?

#1 Post by Leehua »

I keep getting an error when it comes to "If Statements" that are more than three that don't just use "True" or "False" variables. This has to be simple but the documentation seems to be contradictory...

I followed this documentation but didnt work
https://www.renpy.org/wiki/renpy/doc/tu ... er_Choices

I tried this one as well but didn't work:
https://www.reddit.com/r/DDLCMods/comme ... g_choices/

Also tried this one and didn't work:
viewtopic.php?t=33554

I am just trying to have three types of responses to a question like agree, neutral, and disagree with if statements regarding the players selection.

but whether I use:

Code: Select all

$ flag01 = "agree"

Code: Select all

if flag01 == "agree"
or

Code: Select all

$ persistent.(flag01) = (neutral)

Code: Select all

if persistent.(flag01) == (neutral)
all the if statements come back with "reached end of the line when expecting (line of code).

here's what I've been trying to create.

Code: Select all

    menu: 
        "One":
            jump choice001_one
        "Two":
            jump choice001_two
        "Three":
            jump choice001_three

label choice001_one: #Add Default?

    $ flag01 = "agree"
    e "One is Great!"
    jump choice001_done

label choice001_two:

    $ persistent.(flag01) = (neutral)
    e "Two is Better!"
    jump choice001_done

label choice001_three:

    $ persistent.(flag01) = (disagree)
    e "Three is Best!"
    jump choice001_done


    if flag01 == "agree"
        e "First Choice Agree"

    if persistent.(flag01) == (neutral)
        e "Second Choice Neutral"

    if persistent.(flag01) == (disagree)
        e "Third Choice Disagree"


label choice001_done:

    e "Three choices in total."    
help would be appreciated!

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Python "if statements" not working?

#2 Post by isobellesophia »

I think default or the define will work.

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

Code: Select all

default flag01 = "agree"
Or

Code: Select all

define flag01 = "agree"
For the persistent

Code: Select all

default persistent.(flag01) = (neutral)

Code: Select all

define persistent.(flag01) = (neutral)
You should try this one, because it worked for me as variables :)

The $ you can only add this when you are about to use it.

Code: Select all

$ points += 1
Remember, you should define it before the label starts
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
Karl_C
Veteran
Posts: 232
Joined: Sun Mar 31, 2013 6:18 am
Contact:

Re: Python "if statements" not working?

#3 Post by Karl_C »

Code: Select all

  if flag01 == "agree":

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Python "if statements" not working?

#4 Post by xavimat »

You need a colon at the end of the "if" line (see Karl_C answer)
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

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: Python "if statements" not working?

#5 Post by trooper6 »

As always, let me make the post I almost always make.

default vs. define.

default is for when that variable with change.
define is for when that variable will never change.

Don't use define for variables that will change.
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

Post Reply

Who is online

Users browsing this forum: No registered users