Page 1 of 1

Problem with NameErro in a if menu or Expected statement with default.

Posted: Thu Dec 19, 2019 5:02 pm
by Logrent
Hello everyone,

I have a problem with my script on Renpy and could... no in fact, I really need a hand. I'm just tearing my hair out in frustration since two days. I'm trying to do a pretty simple thing I guess : The player can ask five question to a PNJ. Four are true question, the last one is just to proceed with the game. I want to make a question disapear when it is asked, and then, go back to the other questions not asked.

I have that error screen :

Code: Select all

I'm sorry, but an uncaught exception occurred.

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

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

Full traceback:
  File "D:\Guillaume\Bureau\renpy-6.16.5-fr\renpy\execution.py", line 288, in run
    node.execute()
  File "D:\Guillaume\Bureau\renpy-6.16.5-fr\renpy\ast.py", line 1309, in execute
    choice = renpy.exports.menu(choices, self.set)
  File "D:\Guillaume\Bureau\renpy-6.16.5-fr\renpy\exports.py", line 550, in menu
    if renpy.python.py_eval(condition) ]
  File "D:\Guillaume\Bureau\renpy-6.16.5-fr\renpy\python.py", line 1342, in py_eval
    return eval(py_compile(source, 'eval'), globals, locals)
  File "game/script.rpy", line 589, in <module>
    "Why Now ?" if question_first == True:
NameError: name 'question_first' is not defined
It said that my varibale question_first is not define or :

Code: Select all

 $ bitchy = True
$ corruption = 0
$ love = 0
$ question_first = None
$ question_second = True
$ question_third = True
$ question_fourth = True 
It is defined right here. I tried changing things many time (True, False, "True", "False, None...), but that's not working.

I read many tutorial but I can't find my mistake. I read in this forum that I should change the "$" by "default". I tried that, but then my game dont lunch and I have that error,

Code: Select all

 I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/script.rpy", line 51: expected statement.
    default bitchy = None
                   ^

File "game/script.rpy", line 52: expected statement.
    default corruption = 0
                       ^

File "game/script.rpy", line 53: expected statement.
    default love = 0
                 ^

File "game/script.rpy", line 54: expected statement.
    default question_first = None
                           ^

File "game/script.rpy", line 55: expected statement.
    default question_second = True
                            ^

File "game/script.rpy", line 56: expected statement.
    default question_third = True
                           ^

File "game/script.rpy", line 57: expected statement.
    default question_fourth = True
                            ^ 


and I don't know what is wrong. I read some tutorial (Outdated?) for menu with if and varible with default and I don't know what is different in my code.

Here are the line for the menu with if.

Code: Select all

  label questionmenu :

    log "We deeply apologize. If you have any question, I’m willing to answer them."

    menu :    
        "Why Now ?" if question_first == True:
            $ question_first = False
            jump questionN1
        
        "third one" if question_second == True:
            $ question_second = False
            jump questionN2
        
        "second one" if question_third == True:
            $ question_third = False
            jump questionN3
        
        "First one" if question_fourth == True:
            $ question_fourth = False
            jump questionN4
    
        "Nan, it’s alright. Let me sleep.":
            jump endquestion

label questionN1 :
    blablabla
    jump questionmenu

label questionN2 :
    blabla
    jump questionmenu

label questionN3 :
    blablabla
    jump questionmenu

label questionN4 :
    blablabla
    jump questionmenu

label endquestion :
log "In fact, it’s already daylight !"
log "Well, good bye for now my friend. We should meet again." 
Once again, I tried many thing with th if statement. Without the True, or False etc... but I can't make it working.

Someone is willing to help me please?

Thanks for reading!

Re: Problem with NameErro in a if menu or Expected statement with default.

Posted: Thu Dec 19, 2019 5:58 pm
by Per K Grok
Logrent wrote: Thu Dec 19, 2019 5:02 pm Hello everyone,

I have a problem with my script on Renpy and could... no in fact, I really need a hand. I'm just tearing my hair out in frustration since two days. I'm trying to do a pretty simple thing I guess : The player can ask five question to a PNJ. Four are true question, the last one is just to proceed with the game. I want to make a question disapear when it is asked, and then, go back to the other questions not asked.


I've set your code up like this and it runs without problem for me.

Code: Select all


default question_first = False
default question_second = True
default question_third = True
default question_fourth = True

label start:
    jump questionmenu
    
label questionmenu :

    "We deeply apologize. If you have any question, I’m willing to answer them."

    menu :
        "Why Now ?" if question_first == True:
            $ question_first = False
            jump questionN1

        "third one" if question_second == True:
            $ question_second = False
            $ question_first = True
            jump questionN2

        "second one" if question_third == True:
            $ question_third = False
            jump questionN3

        "First one" if question_fourth == True:
            $ question_fourth = False
            jump questionN4

        "Nan, it’s alright. Let me sleep.":
            jump endquestion

label questionN1 :
    "blablabla"
    jump questionmenu

label questionN2 :
    "blabla"
    jump questionmenu

label questionN3 :
    "blablabla"
    jump questionmenu

label questionN4 :
    "blablabla"
    jump questionmenu

label endquestion :
    "In fact, it’s already daylight !"
    "Well, good bye for now my friend. We should meet again."
    



Re: Problem with NameErro in a if menu or Expected statement with default.

Posted: Thu Dec 19, 2019 8:35 pm
by Logrent
Well, I just retry with Copy/Paste your code and....

Once again I have that.

Code: Select all

 I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/script.rpy", line 52: expected statement.
    default bitchy = None
                   ^

File "game/script.rpy", line 53: expected statement.
    default corruption = 0
                       ^

File "game/script.rpy", line 54: expected statement.
    default love = 0
                 ^

File "game/script.rpy", line 56: expected statement.
    default question_first = False
                           ^

File "game/script.rpy", line 57: expected statement.
    default question_second = True
                            ^

File "game/script.rpy", line 58: expected statement.
    default question_third = True
                           ^

File "game/script.rpy", line 59: expected statement.
    default question_fourth = True
                            ^

Ren'Py Version: Ren'Py 6.16.5.525
 
Is there something before the default? Like a line to lunch Python or something like that?

Re: Problem with NameErro in a if menu or Expected statement with default.

Posted: Thu Dec 19, 2019 8:45 pm
by philat
well you're on renpy 6.16...

Re: Problem with NameErro in a if menu or Expected statement with default.

Posted: Fri Dec 20, 2019 1:37 am
by Per K Grok
Logrent wrote: Thu Dec 19, 2019 8:35 pm Well, I just retry with Copy/Paste your code and....

Once again I have that.

Code: Select all

 I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/script.rpy", line 52: expected statement.
    default bitchy = None
                   ^

-----

Ren'Py Version: Ren'Py 6.16.5.525
 
Is there something before the default? Like a line to lunch Python or something like that?

No I have nothing before the 'default'-lines in the code. And I did not include bitchy, corruption or love, since those variables was not used in the code. So apparently you did not only use the code as I wrote it. Do you have any lines of code before the default?

Re: Problem with NameErro in a if menu or Expected statement with default.

Posted: Fri Dec 20, 2019 7:07 am
by Logrent
philat wrote: Thu Dec 19, 2019 8:45 pm well you're on renpy 6.16...
Yeah, I download it from a Frech site who translate Renpy. I'm goign to update it.

[/quote]

No I have nothing before the 'default'-lines in the code. And I did not include bitchy, corruption or love, since those variables was not used in the code. So apparently you did not only use the code as I wrote it. Do you have any lines of code before the default?
[/quote]

Oh sorry, since it was the same thing for me, I didn't mention, the other varible. My bad.

Before the default, I only have some "image" line and "define" character.

I'm goign to download the last update of Renpy and see if it worked out.

Re: Problem with NameErro in a if menu or Expected statement with default.

Posted: Fri Dec 20, 2019 11:24 am
by isobellesophia
I dont think the old version of RenPy havent released a define and default function, so you are go with the new version instead.

Re: Problem with NameErro in a if menu or Expected statement with default.

Posted: Sun Jan 05, 2020 11:20 pm
by Logrent
Alright, I try again and it's working with the newest Renpy version.

Thanks to the people who help me, It's on me. I download from a french Renpy community who wwere not up to date.

The code work just fine.