NameError: global name 'name' is not defined

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.
Message
Author
pfranzen
Regular
Posts: 42
Joined: Fri Apr 01, 2016 2:39 pm
Completed: Cat President 1+2, Internet Court, Too Many Santas, The Awkward Steve Duology, The Pizza Delivery Boy Who Saved the World, Francy Droo & Friends
Organization: Oh, a Rock! Studios
itch: oharock
Contact:

NameError: global name 'name' is not defined

#1 Post by pfranzen »

Does this error mean anything to anyone? It came up for one of our users when they reached the first decision point and selected one of the options. Then whenever they tried to launch the game, they would get the same error.

They haven't been able to repeat it since then, though, and no one else has reported this bug, so...*shrug*?

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/case 1.rpy", line 42, in <module>
NameError: global name 'name' is not defined

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

Full traceback:
  File "renpy/bootstrap.py", line 326, in bootstrap
    renpy.main.main()
  File "renpy/main.py", line 617, in main
    run(restart)
  File "renpy/main.py", line 148, in run
    renpy.execution.run_context(True)
  File "renpy/execution.py", line 922, in run_context
    context.run()
  File "case 1.rpyc", line 42, in script
  File "case 1.rpyc", line 42, in script
  File "renpy/ast.py", line 922, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "renpy/python.py", line 2218, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "game/case 1.rpy", line 42, in <module>
  File "renpy/exports.py", line 1525, in pause
    rv = renpy.ui.interact(mouse='pause', type='pause', roll_forward=roll_forward, pause=delay)
  File "renpy/ui.py", line 298, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "renpy/display/core.py", line 3101, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, **kwargs)
  File "renpy/display/core.py", line 3897, in interact_core
    renpy.display.behavior.skipping(ev)
  File "renpy/display/behavior.py", line 272, in skipping
    if map_keyup(ev, "skip") or map_event(ev, "stop_skipping"):
  File "renpy/display/behavior.py", line 242, in map_keyup
    if (name in ev.eventnames) and ev.up:
NameError: global name 'name' is not defined

Windows-10-10.0.19041
Ren'Py 7.4.3.1414
Internet Court 1.0
Wed Mar 31 20:09:24 2021

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: NameError: global name 'name' is not defined

#2 Post by rayminator »

look at case 1.rpy line 42 copy at least 10 line of code above and below that line and post it here

it has to do something with

Code: Select all

if (name in ev.eventnames) and ev.up:

pfranzen
Regular
Posts: 42
Joined: Fri Apr 01, 2016 2:39 pm
Completed: Cat President 1+2, Internet Court, Too Many Santas, The Awkward Steve Duology, The Pizza Delivery Boy Who Saved the World, Francy Droo & Friends
Organization: Oh, a Rock! Studios
itch: oharock
Contact:

Re: NameError: global name 'name' is not defined

#3 Post by pfranzen »

rayminator wrote: Mon Apr 05, 2021 6:55 pm look at case 1.rpy line 42 copy at least 10 line of code above and below that line and post it here
Here we go! Warning: Messy.
Also warning: This is an FMV game, not a visual novel, so it's more movie- than text- and image-based.

Code: Select all

scene black

pause .75

$ renpy.music.set_volume(2.5, delay=0, channel='real_music') 
$ renpy.music.set_volume(1, delay=0, channel='movie') 

play real_music "music/Morusque - Out of this Room.ogg" loop
scene title 1
$ renpy.pause(5.5, hard=True) 

# Opening confessional scene

scene c1 start
play movie "videos/case 1/case 1-c1.ogv" noloop
show confess_movie 
show subtitle c1-super 
with Dissolve(0)

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: NameError: global name 'name' is not defined

#4 Post by Imperf3kt »

You have a scene called c1 start
I would suggest renaming this to not use "start" in its name as Renpy may be confusing it with the start label which is in the reserved names index.

A well known cause of the global name error is having two start labels.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

pfranzen
Regular
Posts: 42
Joined: Fri Apr 01, 2016 2:39 pm
Completed: Cat President 1+2, Internet Court, Too Many Santas, The Awkward Steve Duology, The Pizza Delivery Boy Who Saved the World, Francy Droo & Friends
Organization: Oh, a Rock! Studios
itch: oharock
Contact:

Re: NameError: global name 'name' is not defined

#5 Post by pfranzen »

I'll fix that, thank you!!

pfranzen
Regular
Posts: 42
Joined: Fri Apr 01, 2016 2:39 pm
Completed: Cat President 1+2, Internet Court, Too Many Santas, The Awkward Steve Duology, The Pizza Delivery Boy Who Saved the World, Francy Droo & Friends
Organization: Oh, a Rock! Studios
itch: oharock
Contact:

Re: NameError: global name 'name' is not defined

#6 Post by pfranzen »

Update! Another user is experiencing the same issue, after I implemented the above change. The game is continuing to crash whenever they load it, even after restarting their computer. The error message is a little different (there's something about the splash screen now?):

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00start.rpy", line 234, in script call
    call _splashscreen from _call_splashscreen_1
  File "renpy/common/00start.rpy", line 234, in script call
    call _splashscreen from _call_splashscreen_1
  File "renpy/common/000statements.rpy", line 453, in execute_pause
    renpy.pause(delay)
NameError: global name 'name' is not defined

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

Full traceback:
  File "renpy/bootstrap.py", line 326, in bootstrap
    renpy.main.main()
  File "renpy/main.py", line 617, in main
    run(restart)
  File "renpy/main.py", line 148, in run
    renpy.execution.run_context(True)
  File "renpy/execution.py", line 922, in run_context
    context.run()
  File "renpy/common/00start.rpy", line 234, in script call
    call _splashscreen from _call_splashscreen_1
  File "script.rpyc", line 197, in script
  File "renpy/common/00start.rpy", line 234, in script call
    call _splashscreen from _call_splashscreen_1
  File "script.rpyc", line 197, in script
  File "renpy/ast.py", line 1969, in execute
    self.call("execute")
  File "renpy/ast.py", line 1957, in call
    return renpy.statements.call(method, parsed, *args, **kwargs)
  File "renpy/statements.py", line 278, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 453, in execute_pause
    renpy.pause(delay)
  File "renpy/exports.py", line 1525, in pause
    rv = renpy.ui.interact(mouse='pause', type='pause', roll_forward=roll_forward, pause=delay)
  File "renpy/ui.py", line 298, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "renpy/display/core.py", line 3101, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, **kwargs)
  File "renpy/display/core.py", line 3897, in interact_core
    renpy.display.behavior.skipping(ev)
  File "renpy/display/behavior.py", line 272, in skipping
    if map_keyup(ev, "skip") or map_event(ev, "stop_skipping"):
  File "renpy/display/behavior.py", line 242, in map_keyup
    if (name in ev.eventnames) and ev.up:
NameError: global name 'name' is not defined

Windows-10-10.0.19041
Ren'Py 7.4.3.1414
Internet Court 1.0
Tue Apr 13 12:04:46 2021

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: NameError: global name 'name' is not defined

#7 Post by rayminator »

python doesn't like spaces

I don't why you are using () in a if statements

Code: Select all

if (name in ev.eventnames) and ev.up:
try it like this

Code: Select all

if name_in_ev.eventnames and ev.up:

pfranzen
Regular
Posts: 42
Joined: Fri Apr 01, 2016 2:39 pm
Completed: Cat President 1+2, Internet Court, Too Many Santas, The Awkward Steve Duology, The Pizza Delivery Boy Who Saved the World, Francy Droo & Friends
Organization: Oh, a Rock! Studios
itch: oharock
Contact:

Re: NameError: global name 'name' is not defined

#8 Post by pfranzen »

Got it! I'll see if that's something in I fix. That's not in a script file I created; that's something Ren'py auto-generated.

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: NameError: global name 'name' is not defined

#9 Post by rayminator »

pfranzen wrote: Wed Apr 14, 2021 2:13 pm Got it! I'll see if that's something in I fix. That's not in a script file I created; that's something Ren'py auto-generated.
can you share you game so we can look at it?

pfranzen
Regular
Posts: 42
Joined: Fri Apr 01, 2016 2:39 pm
Completed: Cat President 1+2, Internet Court, Too Many Santas, The Awkward Steve Duology, The Pizza Delivery Boy Who Saved the World, Francy Droo & Friends
Organization: Oh, a Rock! Studios
itch: oharock
Contact:

Re: NameError: global name 'name' is not defined

#10 Post by pfranzen »

I can share the Steam link! Not the full game though; it's a commercial release. (The initial bug report came literally the day before release.)

https://store.steampowered.com/app/1286 ... net_Court/

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: NameError: global name 'name' is not defined

#11 Post by RicharDann »

NameError: global name 'name' not defined means that somewhere in your code, before that if statement is called, there should exist a variable called name. The error message is pointing at an if statement that's trying to reference that variable's value but cannot find it.

Are you sure that name is being set to a value before that line runs?

For example:

Code: Select all

# Before label start
default name = 'event01'

Code: Select all

# In the label where the if statement is found
label event_01:
     $ name = 'event01'

     if (name in ev.eventnames) and ev.up:
         "Event 1 is running"
It is impossible to know for sure what is causing the problem without looking at the actual code. I'm going to assume what you posted earlier is the code found inside and below that if statement, but that doesn't seem related. What we need is probably what's above, the definition of the name variable.
The most important step is always the next one.

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: NameError: global name 'name' is not defined

#12 Post by rayminator »

pfranzen wrote: Thu Apr 15, 2021 11:43 am I can share the Steam link! Not the full game though; it's a commercial release. (The initial bug report came literally the day before release.)

https://store.steampowered.com/app/1286 ... net_Court/
we need the actual code

we are not willing to pay to help you with something we don't want if you need help we need the code inside the rpy files

pfranzen
Regular
Posts: 42
Joined: Fri Apr 01, 2016 2:39 pm
Completed: Cat President 1+2, Internet Court, Too Many Santas, The Awkward Steve Duology, The Pizza Delivery Boy Who Saved the World, Francy Droo & Friends
Organization: Oh, a Rock! Studios
itch: oharock
Contact:

Re: NameError: global name 'name' is not defined

#13 Post by pfranzen »

rayminator wrote: Thu Apr 15, 2021 4:59 pm we are not willing to pay to help you with something we don't want if you need help we need the code inside the rpy files
I'm sorry, I didn't mean to suggest you should buy the game. I was showing why sharing the game/code on here wasn't doable.

pfranzen
Regular
Posts: 42
Joined: Fri Apr 01, 2016 2:39 pm
Completed: Cat President 1+2, Internet Court, Too Many Santas, The Awkward Steve Duology, The Pizza Delivery Boy Who Saved the World, Francy Droo & Friends
Organization: Oh, a Rock! Studios
itch: oharock
Contact:

Re: NameError: global name 'name' is not defined

#14 Post by pfranzen »

RicharDann wrote: Thu Apr 15, 2021 2:49 pm What we need is probably what's above, the definition of the name variable.
So! That's one of the more confusing aspects of the bug. I don't have or call a variable that's just called named "name" anywhere in the game. The closest I have is "config.name", which is defined in the options screen and I believe comes standard with Ren'py:

Code: Select all

## Basics ######################################################################

## A human-readable name of the game. This is used to set the default window
## title, and shows up in the interface and error reports.
##
## The _() surrounding the string marks it as eligible for translation.

define config.name = _("Internet Court")


## Determines if the title given above is shown on the main menu screen. Set
## this to False to hide the title.

define gui.show_name = True
And similarly build.name:

Code: Select all

## A short name for the game used for executables and directories in the built
## distribution. This must be ASCII-only, and must not contain spaces, colons,
## or semicolons.

define build.name = "InternetCourt"
There's also "save_name", which I define at the beginning of each case (warning, messy code, again):

Code: Select all

label case_2:

$ save_name = "Case #2"
$ persistent.anystrikes = "no"

stop real_music

pause 3.25

$ renpy.music.set_volume(2.25, delay=0, channel='real_music') 

scene black

play real_music "music/Morusque - Village 2.ogg" noloop
scene title 2
$ renpy.pause(5.125, hard=True)

# Opening confessional scene    
This defines what save file should be labeled in the save/load menu; I picked it up from the Ren'py documentation: https://www.renpy.org/doc/html/save_loa ... -save_name.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: NameError: global name 'name' is not defined

#15 Post by Imperf3kt »

The "name" variable is an internal renpy thing, it's not something you added.

The issue is that something in your code is breaking, and the error just happens to occur when renpy is doing something else. It's likely nothing to do with the actual error, just that it's being caught at that moment.


If the game is commercial, you can strip the dialogue, images and audio before sharing. Those things generally aren't necessary for debugging.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]