Need help with menu/if 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
Ubertoast
Newbie
Posts: 3
Joined: Sat Dec 11, 2010 8:01 am
Contact:

Need help with menu/if statements

#1 Post by Ubertoast »

Hi guys,

I'm working on a game, and up to this point it's all been going rather well. I'm having errors in two different places, and even after jigging around a bit I can't seem to solve them. I did a quick search of the forum and I couldn't see anything relevant (though there's a chance I might have overlooked something), so I'm kinda hoping you guys will be able to help me figure this out. The first error occurs here:

Code: Select all

menu:
    "Yes..." if $ tessrelationship >= 105:
          jump DAY_2EVENINGALECHOUSEN1
    "Yes..." if $ tessrelationship <= 104:
         $ tessrelationship +=0
    "Is that not obvious? Why else would I be here?":
        $ tessrelationship -=5
Having it without the second "Yes" option and having the "if" for the jump doesn't seem to help (I want the jump to ONLY occur if the criteria is met). It throws up an "invalid syntax on (line with if statement)."

The same error occurs with the following:

Code: Select all

menu: 
    "In that case.... let's go." if skiptoclass = True:
             $ suerelationship +=5
             jump DAY_3CLASS 
    "In that case... let's go."  if skiptoclass = False:
             $ suerelationship +=5
             jump DAY_3CAFETERIA
    "I don't walk with girls.":
        $ suerelationship -=5
        jump DAY_3BEFORESCHOOLGATES
Here, I'm trying to get it to check a variable, which should have been set earlier (I double checked, it's also set at initialisation to False, along with all the other variables the game needs.)

There's also another one after this point which I havn't been able to test, because I can't actually get to that point. It follows the same formatting as above though, which I started using after reading the Ren'Py language reference on the wiki.

Thanks in advance for any help you can give.

EDIT: Here's the traceback:

Code: Select all

I'm sorry, but an uncaught exception occurred.

SyntaxError: invalid syntax (game/game/script.rpy, line 187)

While running game code:
 - script at line 186 of D:\bcb\game/game/script.rpy

-- Full Traceback ------------------------------------------------------------

  File "D:\renpy-6.11.2\renpy\bootstrap.py", line 270, in bootstrap
  File "D:\renpy-6.11.2\renpy\main.py", line 310, in main
  File "D:\renpy-6.11.2\renpy\main.py", line 93, in run
  File "D:\renpy-6.11.2\renpy\execution.py", line 259, in run
  File "D:\renpy-6.11.2\renpy\ast.py", line 1133, in execute
  File "D:\renpy-6.11.2\renpy\exports.py", line 371, in menu
  File "D:\renpy-6.11.2\renpy\python.py", line 994, in py_eval
  File "D:\renpy-6.11.2\renpy\python.py", line 243, in py_compile
SyntaxError: invalid syntax (game/game/script.rpy, line 187)

While running game code:
 - script at line 186 of D:\bcb\game/game/script.rpy

Ren'Py Version: Ren'Py 6.11.2b

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: Need help with menu/if statements

#2 Post by Aleema »

Okay, let me see what I can fix here. First set of code:

Code: Select all

menu:
    "Yes..." if tessrelationship >= 105:
        jump DAY_2EVENINGALECHOUSEN1
    "Yes..." if tessrelationship <= 104:
        $ tessrelationship +=0
    "Is that not obvious? Why else would I be here?":
        $ tessrelationship -=5
I removed the $ signs after the menu choice. Those aren't attached to variables all the time. In fact, only in the base level of label and init blocks. If you use any python or Ren'Py function, you only have to call the var name.

Code: Select all

menu: 
    "In that case.... let's go." if skiptoclass == True:
        $ suerelationship +=5
        jump DAY_3CLASS 
    "In that case... let's go."  if skiptoclass == False:
        $ suerelationship +=5
        jump DAY_3CAFETERIA
    "I don't walk with girls.":
        $ suerelationship -=5
        jump DAY_3BEFORESCHOOLGATES
When comparing values, in this case skiptoclass and True/False, you need TWO equals signs. For anything else, like <= or => or != etc, you only need one. But you need TWO to see if they're equal.

Also, to save you on writing, "if skiptoclass:" is the exact same as "if skiptoclass == True:", and "if not skiptoclass:" is the same as checking for False.

And for BOTH scripts, I fixed your indentation. If you look at your script before, all your results to the menu options were at different locations. They all need to be at the SAME indentation, so that they're recognized as equal. So always check for extra spaces in front of your lines and make sure that everything is as uniform as possible. That's how this programming language works!

Ubertoast
Newbie
Posts: 3
Joined: Sat Dec 11, 2010 8:01 am
Contact:

Re: Need help with menu/if statements

#3 Post by Ubertoast »

Excellent, thanks Aleema! Guess I should read up a little more on scripting before I carry on :P

Thanks for the help!

Post Reply

Who is online

Users browsing this forum: Google [Bot], RandomHuman64