Trouble Setting a Variable

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
myke
Newbie
Posts: 7
Joined: Thu Apr 07, 2016 11:31 am
Contact:

Trouble Setting a Variable

#1 Post by myke » Mon Apr 25, 2016 1:42 pm

So I'm having trouble keeping this in line. Granted, I am checking the outdated wiki when double checking my work, but in a previous project this worked.

At the start of my script I have a variable declared as

$ touched_wall = False

And further along I have an option that should activate it, or, if already activated leads to another path.

label walltouch:
if $ touched_wall = true:
jump walltouch2

else:
$ touched_wall = true

And beneath that it goes to the dialogue for that section.

But when I try to set that option in game i get this:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 369, in script
    if $ touched_wall = true:
SyntaxError: invalid syntax (script.rpy, line 369)

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

Full traceback:
  File "game/script.rpy", line 369, in script
    if $ touched_wall = true:
  File "/Users/mike/Downloads/renpy-6.99.8-sdk/renpy/ast.py", line 1648, in execute
    if renpy.python.py_eval(condition):
  File "/Users/mike/Downloads/renpy-6.99.8-sdk/renpy/python.py", line 1605, in py_eval
    code = py_compile(code, 'eval')
  File "/Users/mike/Downloads/renpy-6.99.8-sdk/renpy/python.py", line 512, in py_compile
    raise e
SyntaxError: invalid syntax (script.rpy, line 369)

Darwin-14.5.0-x86_64-i386-64bit
Ren'Py 6.99.10.1227
Maze 0.0
Why is this happening to me? D:

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

Re: Trouble Setting a Variable

#2 Post by drKlauz » Mon Apr 25, 2016 2:17 pm

$ symbol in front of line means it's python code
You assign value by =, but check by ==
Also python and renpy very indentation sensitive, check your spaces

Your code probably should looks like this

Code: Select all

label start:
  $walltouched=False

label touchwall:
  if walltouched==True:
    jump touchwall2
  "you look around, but find nothing"
  $walltouched=True
  jump touchwall

label touchwall2:
  "you found hidden door"

myke
Newbie
Posts: 7
Joined: Thu Apr 07, 2016 11:31 am
Contact:

Re: Trouble Setting a Variable

#3 Post by myke » Mon Apr 25, 2016 6:05 pm

I appreciate the help and that did solve that issue, but now it's saying that i've not declared the variable despite it having been set up top.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Trouble Setting a Variable

#4 Post by namastaii » Mon Apr 25, 2016 6:32 pm

Code: Select all

label start:
    $ touched_wall = False
    



label walltouch:
    if touched_wall:
        jump walltouch2
    else:
        $ touched_wall = True
        
        
####you can use - if touched_wall:
#               - if touched_wall == True:
#               - if touched_wall is True:
***Don't use $ in the IF statement. Don't use one '=' when checking the value of a variable. This is for assigning values ONLY. Use two: == or if you just say 'if touched_wall:' then it is automatically checking to see if the variable is True.

myke
Newbie
Posts: 7
Joined: Thu Apr 07, 2016 11:31 am
Contact:

Re: Trouble Setting a Variable

#5 Post by myke » Mon Apr 25, 2016 9:28 pm

I've got the variable listed directly beneath the start label, but starting and getting to the option still gives me the error exception of it not being defined.

Code: Select all

I'm sorry, but an uncaught exception occurred.

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

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Trouble Setting a Variable

#6 Post by namastaii » Mon Apr 25, 2016 10:15 pm

Well what does the whole thing look like? And you can try putting the variable under an 'init' instead then.

Code: Select all

init:
    ###$ touched_wall = False ---this best way:
    default touched_wall = False

label start:

    "blah blah"
    jump walltouch

What do you mean by option? How do you have this set up?
Last edited by namastaii on Tue Apr 26, 2016 1:58 am, edited 1 time in total.

myke
Newbie
Posts: 7
Joined: Thu Apr 07, 2016 11:31 am
Contact:

Re: Trouble Setting a Variable

#7 Post by myke » Mon Apr 25, 2016 10:47 pm

That's fixed it! Thanks a lot. But by option, I meant menu option. The setup I had was this would have a different result if the same choice was a second time.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Trouble Setting a Variable

#8 Post by trooper6 » Tue Apr 26, 2016 1:30 am

Please note: current best practices is to define your variables so:

Code: Select all

default touched_wall = False

label start:
    "Blah blah"
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Trouble Setting a Variable

#9 Post by namastaii » Tue Apr 26, 2016 1:57 am

Right. I keep forgetting.

Post Reply

Who is online

Users browsing this forum: Google [Bot]