Creating a music channel

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
Potato0095
Regular
Posts: 84
Joined: Sun May 08, 2016 8:40 pm
Projects: LoveCraft
itch: potato95
Location: Brazil
Contact:

Creating a music channel

#1 Post by Potato0095 »

Hi, I want to create a music channel, my question is: how. I'm trying to use a string I found in the sound doc:

Code: Select all

renpy.music.register_channel("sfx1", "sfx")
It gives me the error "expected statement", so I just used a $ (creating a single Python statement). Ren'Py at first accepts it (the game launchs it), but when the string comes, gives me another error.
While running game code:
File "game/script.rpy", line 231, in script
$ renpy.music.register_channel("sfx1", "sfx")
File "game/script.rpy", line 231, in <module>
$ renpy.music.register_channel("sfx1", "sfx")
Exception: Can't register channel outside of init phase.

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

Full traceback:
File "game/script.rpy", line 231, in script
$ renpy.music.register_channel("sfx1", "sfx")
File "C:\Users\Potato\Downloads\Ren'py\renpy\ast.py", line 814, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "C:\Users\Potato\Downloads\Ren'py\renpy\python.py", line 1719, in py_exec_bytecode
exec bytecode in globals, locals
File "game/script.rpy", line 231, in <module>
$ renpy.music.register_channel("sfx1", "sfx")
File "C:\Users\Potato\Downloads\Ren'py\renpy\audio\audio.py", line 676, in register_channel
raise Exception("Can't register channel outside of init phase.")
Exception: Can't register channel outside of init phase.
Making it short, I need a init block, but I don't know anything about it.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Creating a music channel

#2 Post by Ocelot »

https://www.renpy.org/doc/html/python.h ... -statement

In short:

Code: Select all

init python:
    renpy.music.register_channel("sfx1", "sfx")
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: No registered users