"IF" statement issue.(Solved)

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
LeperWeaboo
Newbie
Posts: 2
Joined: Mon Jan 18, 2016 10:57 pm
Contact:

"IF" statement issue.(Solved)

#1 Post by LeperWeaboo » Mon Jan 18, 2016 11:12 pm

Hello there , I need some help so that my "if" statements dont overlap on one another.More info with the images.Thanks.
The ignore button works too , but that isnt really a fix.
Attachments
B.jpg
Entry.
B.jpg (2.38 KiB) Viewed 604 times
A.jpg
Entry.
A.jpg (2.68 KiB) Viewed 604 times
alpha.jpg
This is the error , I would like to know if there is a way to fix this so it is readable without a jump and label.
beta.jpg
I used that form in order to make a connection between answers and scenarios ; but when i try to get to it in the actual game it all seems to overlap and reads the code for each path and not only the one its attached to.
Last edited by LeperWeaboo on Tue Jan 19, 2016 2:17 pm, edited 2 times in total.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: "IF" statement issue.

#2 Post by namastaii » Tue Jan 19, 2016 1:09 am

Could you show more of the code?

User avatar
Iylae
Regular
Posts: 73
Joined: Sat Jan 09, 2016 6:57 am
Location: Cornwall, UK
Contact:

Re: "IF" statement issue.

#3 Post by Iylae » Tue Jan 19, 2016 5:23 am

You're missing a colon on your penultimate line:

Code: Select all

if gift == tortoise :
Also, the error message you're getting tells you the problem you're having: The variable rpe is not defined before line 285 has been run.

Where you have...

Code: Select all

if rpe == "queene" :
You need to ensure that rpe is defined before it, for example:

Code: Select all

rpe == ""
if rpe == "queene" :
Always check your code line that causes the exception, and work your way backwards from that.
Image
  If we are what we repeatedly do, then good coding is not an act, but a habit

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: "IF" statement issue.

#4 Post by Onishion » Tue Jan 19, 2016 8:18 am

Use:

Code: Select all

default rpe = "whatever you want the default to be"
You can put that anywhere and it'll always get loaded into the code, even in a saved game (although it's best to keep these where you can find them). It's relatively new, apparently. But yeah, if you try to use a variable before defining it, errors.

As to your second problem, I'm not exactly sure why that would give unintended results, it should only spit back one of those things at a time, you are missing a ":" after "tortoise, which would cause some issues. Also, you might want to change the "if"s after the first one to "elif"s. In this case it shouldn't have a different result, but it is more efficient, since in the current form, it checks the first one, then even if that one is right, it checks the next, and the next, and so on. If you use elif statements instead, then if the second one passes, it forgets about the third, forth, fifth, etc. and skips to the end of that chain and on to the next thing. Sometimes the checks can be several things and you'd want to check each possibility, but in this case it seems like a single variable with a single possible truth, so making the check as efficient as possible would be nice.

LeperWeaboo
Newbie
Posts: 2
Joined: Mon Jan 18, 2016 10:57 pm
Contact:

Re: "IF" statement issue.

#5 Post by LeperWeaboo » Tue Jan 19, 2016 2:04 pm

Hesus thanks for all the info.

Answering all the questions :
"if gift == tortoise : "I did place the two dots/colon at the end since the script wouldnt work without it.That was just a screen shot taken from here
http://renpy.org/wiki/renpy/doc/tutoria ... er_Choices which doesnt have it , but that is not the issue.

Ive updated the post with further info on how i defined the actions , which i dont think i did much different from what ive been told so far.The only difference i see is the $ at the start.
Ill try the elif command.

Edit:Nvm , i actually changed the "rpe" at two of them since i thought i can change that too.But now i fixed it , sorry to bother you all for this .
Thank you all,especially Onishion.

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: "IF" statement issue.(Solved)

#6 Post by Onishion » Wed Jan 20, 2016 3:45 am

About the $ sign thing, IF you change the variable within a python block, something like

Code: Select all

python:
    Variable = 5
Then you don't need a $. If you put it outside of such a python block, however, which is most of an Renpy game, then you need the $ sign before any line which changes a variable, since that tells Renpy that that line is python code.

Glad you got it working though. ;)

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]