Problem with $if flags [SOLVED! THANKS]

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
User avatar
dreamy
Regular
Posts: 71
Joined: Mon Mar 10, 2014 5:48 am
Organization: Cloud9 Dreams
Tumblr: fey-en
Location: Fluffy clouds
Contact:

Problem with $if flags [SOLVED! THANKS]

#1 Post by dreamy »

Hi! I just started implementing if flags in my game but I seem to have run into a problem. I first put the flag names over here like this:

Code: Select all

# The game starts here.
label start:
    $ magic = False
    $ thief = False

    show black
And one of the flags should get implemented in this menu choice:

Code: Select all

menu:
    "Go outside":
        jump bobble
        
    "Look around":
        jump orb
label orb:
    $ magic = True
    "This shop's concept is actually interesting yet there are so many things questionable here."
And that flag came into play here:

Code: Select all

    if magic:
        "It came from...Rina's other bag. She left it on the table."
    else:
        "I must have imagined it."
However, when I started the game, the following error occurred:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 1358, in script
  File "game/script.rpy", line 1358, in python
NameError: name 'magic' is not defined

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

Full traceback:
  File "C:\Users\Acer\Documents\renpy-6.16.5-sdk\renpy\execution.py", line 288, in run
    node.execute()
  File "C:\Users\Acer\Documents\renpy-6.16.5-sdk\renpy\ast.py", line 1486, in execute
    if renpy.python.py_eval(condition):
  File "C:\Users\Acer\Documents\renpy-6.16.5-sdk\renpy\python.py", line 1342, in py_eval
    return eval(py_compile(source, 'eval'), globals, locals)
  File "game/script.rpy", line 1358, in <module>
    if magic:
NameError: name 'magic' is not defined

Windows-7-6.1.7601-SP1
Ren'Py 6.16.5.525
Chrysanthemum Tea 0.0
I'm not sure what the error is :roll: . Does somebody happen to know what I should do?
Last edited by dreamy on Sun Mar 29, 2015 10:14 am, edited 1 time in total.
"Listen to the silence, it's so blissful...
So calm down and listen..."

Image

Exiscoming
Regular
Posts: 132
Joined: Tue Apr 29, 2014 5:37 pm
Contact:

Re: Problem with $if flags

#2 Post by Exiscoming »

Right now when you jump to label orb you say that magic is True.
So the if statement should be

Code: Select all

 if magic == True:
        "It came from...Rina's other bag. She left it on the table."
    else:
        "I must have imagined it."

I'm only a starter when it comes to coding myself, so this might not be the awnser you were looking for. Lemme know if it helped or not.

Edit:

magic = True (Here you say that magic becomes True)
magic == True (Here you say that magic is True)

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Problem with $if flags

#3 Post by nyaatrap »

dreamy wrote:I just started implementing if flags in my game
Then the first advice is don't use save data. There's no save data compatibility.

User avatar
dreamy
Regular
Posts: 71
Joined: Mon Mar 10, 2014 5:48 am
Organization: Cloud9 Dreams
Tumblr: fey-en
Location: Fluffy clouds
Contact:

Re: Problem with $if flags

#4 Post by dreamy »

Wow! It worked now. Thank you so much! :D
"Listen to the silence, it's so blissful...
So calm down and listen..."

Image

User avatar
Kate
Regular
Posts: 197
Joined: Thu Sep 19, 2013 6:10 pm
Projects: Blackout
Organization: Moonlight Otome
Location: United States
Contact:

Re: Problem with $if flags

#5 Post by Kate »

nyaatrap wrote:
dreamy wrote:I just started implementing if flags in my game
Then the first advice is don't use save data. There's no save data compatibility.
Wait, what? Save data and flags won't work? Can you explain that? I didn't think that was a problem...
Current Project:
Blackout [VN][Romance][GxB][Mystery][Suspense] http://lemmasoft.renai.us/forums/viewto ... 43&t=34118
"It is the duty of authors to make the fantastic seem ordinary and the ordinary seem fantastic." - K. Auer

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Problem with $if flags [SOLVED! THANKS]

#6 Post by philat »

Save files from before you initialized the variables won't work. Save files generated after you changed the script work fine.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]