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

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
Logrent
Newbie
Posts: 5
Joined: Thu Dec 19, 2019 7:53 am
Contact:

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

#1 Post 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!

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

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

#2 Post 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."
    



User avatar
Logrent
Newbie
Posts: 5
Joined: Thu Dec 19, 2019 7:53 am
Contact:

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

#3 Post 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?

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

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

#4 Post by philat »

well you're on renpy 6.16...

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

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

#5 Post 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?

User avatar
Logrent
Newbie
Posts: 5
Joined: Thu Dec 19, 2019 7:53 am
Contact:

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

#6 Post 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.

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

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

#7 Post 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.
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
Logrent
Newbie
Posts: 5
Joined: Thu Dec 19, 2019 7:53 am
Contact:

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

#8 Post 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.

Post Reply

Who is online

Users browsing this forum: Google [Bot]