_preferences.volumes['music'] generates "KeyError" [solved]

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
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

_preferences.volumes['music'] generates "KeyError" [solved]

#1 Post by korova »

OK, I'm doomed tonight.

Several codes that used to work perfectly now randomly generate errors.

I need to get the value of mixer volumes.
I use the variable _preferences.volumes['music'] and _preferences.volumes['sfx'], and later pass them to a screen.

This worked like a charm, and suddenly generates errors when I build distributions.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 97, in script
    define quick_boutons = [
  File "game/script.rpy", line 101, in <module>
    "action":Show("ecran_pause",music=_preferences.volumes['music'],son=_preferences.volumes['sfx']),
KeyError: 'music'

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

Full traceback:
  File "C:\Documents and Settings\Korova\Bureau\Clair_Obscur-0.1-win\Clair_Obscur-0.1-win\renpy\bootstrap.py", line 288, in bootstrap
    renpy.main.main()
  File "C:\Documents and Settings\Korova\Bureau\Clair_Obscur-0.1-win\Clair_Obscur-0.1-win\renpy\main.py", line 360, in main
    game.context().run(node)
  File "game/script.rpy", line 97, in script
    define quick_boutons = [
  File "C:\Documents and Settings\Korova\Bureau\Clair_Obscur-0.1-win\Clair_Obscur-0.1-win\renpy\ast.py", line 1716, in execute
    value = renpy.python.py_eval_bytecode(self.code.bytecode)
  File "C:\Documents and Settings\Korova\Bureau\Clair_Obscur-0.1-win\Clair_Obscur-0.1-win\renpy\python.py", line 1472, in py_eval_bytecode
    return eval(bytecode, globals, locals)
  File "game/script.rpy", line 101, in <module>
    "action":Show("ecran_pause",music=_preferences.volumes['music'],son=_preferences.volumes['sfx']),
KeyError: 'music'

Windows-XP-5.1.2600-SP2
Ren'Py 6.99.4.467
clairobscur 0.1
If I try to print the variable _preferences.volumes, it seems that it does have a "music" index.

I had the error once under linux, and now under windows (XP), no problem on Mac OS (I develop either on linux or Mac)

I don't understand the problem, can someone help me ?
Last edited by korova on Thu Jul 02, 2015 1:22 pm, edited 1 time in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: _preferences.volumes['music'] generates "KeyError"

#2 Post by PyTom »

You probably want _preferences.get_volume('music').
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

Re: _preferences.volumes['music'] generates "KeyError"

#3 Post by korova »

Done.

Just for my knowledge, does this function touches the mixers or the channels ? (I always have trouble to make distinction between channels and mixers)

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: _preferences.volumes['music'] generates "KeyError"

#4 Post by PyTom »

The mixer.

Basically, there are a small number of mixers, which are shared by a large number of channels.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

Re: _preferences.volumes['music'] generates "KeyError"

#5 Post by korova »

Thanks. Things are clearer now.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot]