Invalid Syntax.

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
NadOtavlas
Regular
Posts: 38
Joined: Sat Apr 21, 2018 3:46 am
Contact:

Invalid Syntax.

#1 Post by NadOtavlas »

Hey so I'm having some problems with if statements. I keep getting an error telling me my syntax is invalid. Here's my code.

Code: Select all

    "I look into the fridge to get something to eat."
    menu:
        "Limón Cheetos.":
            jump afterfood
            $BP += 1
            $Yummymeal += 1
        "Black Licorice.":
            jump afterfood
    label afterfood:
    if $Yummymeal == 1:
    "I grab the cheetos and have a taste. They're really great today."
    else:
    "I grab a piece of black licorice which I only bought because someone told me to."
    "I only have one bite and I already don't like it."
    return

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Invalid Syntax.

#2 Post by Imperf3kt »

Some small problems. Try this.

Code: Select all

    "I look into the fridge to get something to eat."
    menu:
        "Limón Cheetos.":
            $BP += 1
            $Yummymeal += 1
            jump after food # this should be the last thing done, not the first
            
        "Black Licorice.":
            jump afterfood
            
label afterfood: # labels must be fully left aligned 
    if Yummymeal == 1: # leave the $ symbol off variables
        "I grab the cheetos and have a taste. They're really great today."
    else:
        "I grab a piece of black licorice which I only bought because someone told me to."
        "I only have one bite and I already don't like it."
        return # not necessary
    return
For this setup, I would have used pass instead of jump
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

NadOtavlas
Regular
Posts: 38
Joined: Sat Apr 21, 2018 3:46 am
Contact:

Re: Invalid Syntax.

#3 Post by NadOtavlas »

For this setup, I would have used pass instead of jump
I never heard of "pass" before just right now so that's why I didn't use it.

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: Invalid Syntax.

#4 Post by rayminator »

pass would be like this

Code: Select all

    "I look into the fridge to get something to eat."
    menu:
        "Limón Cheetos.":
            $BP += 1
            $Yummymeal += 1
            pass #This pass will go to the if Yummymeal == 1:
            
        "Black Licorice.":
            pass #This pass will go to else
            

    if Yummymeal == 1: # leave the $ symbol off variables
        "I grab the cheetos and have a taste. They're really great today."
        jump next_label or pass again
    else:
        "I grab a piece of black licorice which I only bought because someone told me to."
        "I only have one bite and I already don't like it."
        pass #This pass will continue on to the rest of the dialogue
        jump next_label or pass again
if you do use pass again make sure the rest of code match else:

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Invalid Syntax.

#5 Post by hell_oh_world »

doesn't matter whether you use pass or jump in that situation, both will yield the same events. `pass` is a python statement that you put inside blocks if you want to leave them empty for now but you're planning to add something inside it later. it does exist because python blocks should contain at least one statement or expression and must not be left blank. so you could say that pass is simply just a placeholder for things.

I think I would prefer having long lines of codes that are more concise and exact to the point, rather than making it shorter but not that direct to the point. all I'm saying is that using jump in your case is much better since its more understandable on where the code should go next. but everyone has their preference for this, it's really up to you. hope that made sense.

Post Reply

Who is online

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