Page 1 of 1
Menu Coding Trouble - Syntax Error [solved]
Posted: Thu Nov 12, 2020 11:18 am
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])
Re: Menu Coding Trouble - Syntax Error
Posted: Thu Nov 12, 2020 12:15 pm
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.
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.
Re: Menu Coding Trouble - Syntax Error
Posted: Thu Nov 12, 2020 1:00 pm
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])
Re: Menu Coding Trouble - Syntax Error
Posted: Thu Nov 12, 2020 1:12 pm
by drKlauz
Same error
Code: Select all
"Handling Shock or Trauma" if homeworld = "spaceship":
Re: Menu Coding Trouble - Syntax Error
Posted: Thu Nov 12, 2020 1:17 pm
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.
Re: Menu Coding Trouble - Syntax Error
Posted: Thu Nov 12, 2020 1:24 pm
by marionline
It works!

Thanks to all of you!