SyntaxError: 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
Night130
Newbie
Posts: 13
Joined: Sun Apr 22, 2018 9:57 am
Contact:

SyntaxError: invalid syntax

#1 Post by Night130 »

I'm not sure what I'm doing wrong. I've looked up different answers and none of them are working. I'm trying to make it so if you go on a date with Cindy, the player will say a different line in the future.

Here is the traceback:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 498, in script
    if cindydate1 = True:
SyntaxError: invalid syntax (game/script.rpy, line 498)

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

Full traceback:
  File "game/script.rpy", line 498, in script
    if cindydate1 = True:
  File "C:\Users\Anya\Desktop\renpy-6.99.14.3-sdk\renpy\ast.py", line 1729, in execute
    if renpy.python.py_eval(condition):
  File "C:\Users\Anya\Desktop\renpy-6.99.14.3-sdk\renpy\python.py", line 1917, in py_eval
    code = py_compile(code, 'eval')
  File "C:\Users\Anya\Desktop\renpy-6.99.14.3-sdk\renpy\python.py", line 674, in py_compile
    raise e
SyntaxError: invalid syntax (game/script.rpy, line 498)

Windows-8-6.2.9200
Ren'Py 6.99.14.3.3347
My Royal Love 1.0
Sun Apr 22 07:04:08 2018
Here are the lines in my editor:

Code: Select all

 label start:
    $ auroradate1 = False 

Code: Select all

 label cindyyes:
    $ cindydate1 == True
    c "Wonderful! Follow me." 

Code: Select all

 if cindydate1 = True:
    "I met Cinderella, who was suppose to show me around the castle. Thanks for telling me by the way..." 

I'm not sure if there is other code you need? Not sure if you also need this information, but I also have other character that you can go on a date with, and depending on who you choose, the player will say different lines, but this is just the first error Renpy showed when I pressed "launch project"

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: SyntaxError: invalid syntax

#2 Post by kivik »

You've got your declaration statements and comparison statements mixed up:

Code: Select all

 label cindyyes:
    $ cindydate1 == True
    c "Wonderful! Follow me." 
Should be:

Code: Select all

 label cindyyes:
    $ cindydate1 = True
    c "Wonderful! Follow me." 
And

Code: Select all

if cindydate1 = True:
    "I met Cinderella, who was suppose to show me around the castle. Thanks for telling me by the way..." 
Should be:

Code: Select all

if cindydate1: # or if cindydate1 == True:
    "I met Cinderella, who was suppose to show me around the castle. Thanks for telling me by the way..." 
Note:
You can do "if variable:" for quick variable checks - if the variable is boolean (True or False) then it'll be evaluated the same as "if variable == True". This is true for most modern programming languages, though I'm old enough to have learnt QBasic and it confused the hell out of me when I was told I could shorten it.

You can get more advanced than that with variables, such as strings to see whether they're empty or not (if string_var: would return True if string_var is not empty; False if string_var is ""). There're standard conventions in most programming languages, but always make sure to read up on the language's way of evaluating these statements

Night130
Newbie
Posts: 13
Joined: Sun Apr 22, 2018 9:57 am
Contact:

Re: SyntaxError: invalid syntax

#3 Post by Night130 »

During the last code, the "I met Cinderella..." I have 2 different options of that line, depending on which character you choose to go on a date with. When I did launch project, I chose the Cinderella route (the route where youre suppose to get the line "I met Cinderella...")I would get an error for the other characters answers. If I pressed ignore, it would play Cinderella's response, then I would get an error for a different response. Should I separate these somehow?
Traceback:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 502, in script
    if alddindate1:
  File "game/script.rpy", line 502, in <module>
    if alddindate1:
NameError: name 'alddindate1' is not defined

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

Full traceback:
  File "game/script.rpy", line 502, in script
    if alddindate1:
  File "C:\Users\Anya\Desktop\renpy-6.99.14.3-sdk\renpy\ast.py", line 1729, in execute
    if renpy.python.py_eval(condition):
  File "C:\Users\Anya\Desktop\renpy-6.99.14.3-sdk\renpy\python.py", line 1919, in py_eval
    return py_eval_bytecode(code, globals, locals)
  File "C:\Users\Anya\Desktop\renpy-6.99.14.3-sdk\renpy\python.py", line 1912, in py_eval_bytecode
    return eval(bytecode, globals, locals)
  File "game/script.rpy", line 502, in <module>
    if alddindate1:
NameError: name 'alddindate1' is not defined

Windows-8-6.2.9200
Ren'Py 6.99.14.3.3347
My Royal Love 1.0
Sun Apr 22 07:51:18 2018
Editor line:

Code: Select all

 $ aladdindate1 = Flase 

Code: Select all

 label alyes:
    $ aladdindate1 = True
    al "Alright then! Let's go this way first" 

Code: Select all

 if aladdindate1:
    "I went into town. I met some of the people in your kingdom." 
I changed the rest of the changes to match what you said

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: SyntaxError: invalid syntax

#4 Post by kivik »

The error is basically saying the variable alddindate1 is not defined, so somehow your code isn't reaching the "$ aladdindate1" line it seems. Try adding the following outside of a label block to initialise it at game launch:

Code: Select all

default aiddindate1 = False
This will default the value at launch and make sure the variable's declared wherever you are in the game.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Majestic-12 [Bot]