Menu Coding Trouble - Syntax Error [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
marionline
Newbie
Posts: 12
Joined: Sat Nov 07, 2020 3:41 pm
Contact:

Menu Coding Trouble - Syntax Error [solved]

#1 Post by marionline »

Hey!
I encountered a syntax error and don't know how to tackle it (please excuse the pokémon pun ;P ).

This doesn't work and I don't know where the error comes from:

Code: Select all

    n "Forget about about the space journey and your job for a moment."
    n "What was you favorite hobby as child?"
    menu:
        "Knowledge on Animals & Plants" if homeworld = "planet":
            python:
                player.skills.append(['Knowledge on Animals & Plants', 1])
While this some lines above seems to work:

Code: Select all

n "Tell me, what were you doing on the spaceship travelling to A1 again?"
    menu:
        "I work as a mechanist.":
            python:
                player.skills.append(['Mechanics', 3])
        "I work as a pilot.":
            python:
                player.skills.append(['IT', 3])
Attachments
error.png
Last edited by marionline on Thu Nov 12, 2020 1:24 pm, edited 1 time in total.

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Menu Coding Trouble - Syntax Error

#2 Post by RicharDann »

This expression:

Code: Select all

"Knowledge on Animals & Plants" if homeworld = "planet":
Should be:

Code: Select all

"Knowledge on Animals & Plants" if homeworld == "planet": #should use == sign instead of =
In python, one equal sign (=) is used only for assigning values, for example with default statement.

Code: Select all

default homeworld = "planet"
When you need to do an equality comparison with if statement, you must use two equal signs (==).

Additionally, if you only need one expression you can invoke functions or any python expression in the script directly by using a $ sign before the expression instead of a python block.

Code: Select all

menu:
    "I work as a mechanist.":
        $ player.skills.append(['Mechanics', 3])
This can help reduce the amount of code blocks and makes it a little easier to debug.
The most important step is always the next one.

marionline
Newbie
Posts: 12
Joined: Sat Nov 07, 2020 3:41 pm
Contact:

Re: Menu Coding Trouble - Syntax Error

#3 Post by marionline »

Thank you!

I tried to fix it.
But the error still persist. :(

I included more code, maybe the error is further up in the code.

Code: Select all

label summary:
    $ home_name = renpy.input("What was this [homeworld] called?")
    $ home_name = home_name.strip()
    if home_name == "":
        $ home_name = "HOMEWORLD"
    else:
        povname "My home is called [home_name]!"
    n "All right. You name is [player.name] and you lived at a [homeworld] called [home_name]."
    n "Tell me, what were you doing on the spaceship travelling to A1 again?"
    menu:
        "I work as a mechanist.":
            python:
                player.skills.append(['Mechanics', 3])
        "I work as a pilot.":
            python:
                player.skills.append(['IT', 3])
        "I'm a botanist.":
            python:
                player.skills.append(['Knowledge on Animals & Plants', 3])
        "I'm a linguist.":
            python:
                player.skills.append(['Research', 3])
        "I'm a soldier.":
            python:
                player.skills.append(['Shooting', 3])
        "I work as a janitor.":
            python:
                player.skills.append(['Planning Ahead', 3])
        "I'm the vicecaptain!":
            python:
                player.skills.append(['Persuasion', 3])
        "I work as a diplomat.":
            python:
                player.skills.append(['Diplomacy', 3])
        "Uhm... I just snug onboard...":
            python:
                player.skills.append(['Hiding & Sneeking', 3])
            n "Oh, really?"
            n "I'm a bit speechless about that..."
            n "Ehm..."

    n "Forget about about the space journey and your job for a moment."
    n "What was you favorite hobby as child?"
    menu:
        "Knowledge on Animals & Plants" if homeworld == "planet":
            $ player.skills.append(['Knowledge on Animals & Plants', 1])
        "Fencing" if homeworld == "planet":
            $ player.skills.append(['Fencing', 1])
        "Fistfighting" if homeworld == "planet":
            $ player.skills.append(['Fistfighting', 1])
        "Hunting" if homeworld == "planet":
            $ player.skills.append(['Hunting', 1])
        "Discovery" if homeworld == "planet":
            $ player.skills.append(['Discovery', 1])
        "Charisma" if homeworld == "planet":
            $ player.skills.append(['Charisma', 1])
        "Planning Ahead" if homeworld == "spaceship":
            $ player.skills.append(['Planning Ahead', 1])
        "Knowledge on certain costumes" if homeworld == "spaceship":
            $ player.skills.append(['Knowledge on certain costumes', 1])
        "Evasion" if homeworld == "spaceship":
            $ player.skills.append(['Evasion', 1])
        "Diplomacy" if homeworld == "spaceship":
            $ player.skills.append(['Diplomacy', 1])
        "Handling Shock or Trauma" if homeworld = "spaceship":
            $ player.skills.append(['Handling Shock or Trauma', 1])
        "Shooting" if homeworld == "spaceship":
            $ player.skills.append(['Shooting', 1])
        "Mechanics" if homeworld == "Moon Dome":
            $ player.skills.append(['Mechanics', 1])
        "MartialArts" if homeworld == "Moon Dome":
            $ player.skills.append(['MartialArts', 1])

drKlauz
Veteran
Posts: 239
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

Re: Menu Coding Trouble - Syntax Error

#4 Post by drKlauz »

Same error

Code: Select all

        "Handling Shock or Trauma" if homeworld = "spaceship":
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Menu Coding Trouble - Syntax Error

#5 Post by RicharDann »

If you look at the traceback and the description of the error, it usually points to the specific line number where the error occurred. In the first case it was in line 263 of your script.rpy file. If you use a text editor like Atom you can see the lines numbered usually to the left to help you quickly locate what is causing the problem.
The most important step is always the next one.

marionline
Newbie
Posts: 12
Joined: Sat Nov 07, 2020 3:41 pm
Contact:

Re: Menu Coding Trouble - Syntax Error

#6 Post by marionline »

It works! :D
Thanks to all of you!

Post Reply

Who is online

Users browsing this forum: Google [Bot]