Ren'Py newbie here, music/soudn problem with renpy code

rokit6/Naxoll

Member
Mar 30, 2019
215
203
Hello!

I don't have much idea about Renpy so I need some help.

There is a game that had music and sounds but in its last update the developer has decided not to add it, but in my opinion I think it is missing that sound and music.
I have tried to copy and paste from their code to add those sounds and music to all of the new content, but they don't work and I don't know why.

The first part of the game is in the script.rpy and the content that does not contain music is in another rpy called 0.9.rpy.

In the script.rpy, the developer uses the play music "audio/xxxxxx.mp3" and the stop music. I am trying to use those same commands in 0.9.rpy but I get an error saying:

I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/0.9.rpy", line 1217, in script
play music "audio/tension.mp3"
Exception: Sayer 'play' is not defined.

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

Full traceback:
File "game/0.9.rpy", line 1217, in script
play music "audio/tension.mp3"
File "renpy/ast.py", line 680, in execute
who = eval_who(self.who, self.who_fast)
File "renpy/ast.py", line 574, in eval_who
raise Exception("Sayer '%s' is not defined." % who)
Exception: Sayer 'play' is not defined.
I don't know how I could fix this, can someone help me?

Thanks.
 
Last edited:

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,561
2,183
play "audio/tension.mp3"
Exception: Sayer 'play' is not defined."

Nice easy one. A simple typo.

play alone is not enough for RenPy to realize it's something to do with audio.
Without the extra parameters, RenPy just assumes it's a character. In the same way e "Hello" might be Eileen speaking. In your case, it thinks it's looking for a character called play.

What you are looking for is either play sound or play music.

See :

Based on your example, I'm assuming play music rather than just play.
 
  • Like
Reactions: rokit6/Naxoll

rokit6/Naxoll

Member
Mar 30, 2019
215
203
Nice easy one. A simple typo.

play alone is not enough for RenPy to realize it's something to do with audio.
Without the extra parameters, RenPy just assumes it's a character. In the same way e "Hello" might be Eileen speaking. In your case, it thinks it's looking for a character called play.

What you are looking for is either play sound or play music.

See :

Based on your example, I'm assuming play music rather than just play.
Hello, thanks u for trying to help me!

Im using the play music followed by the route where is the audio: play music "audio/tension.mp3" as I said in the OP. But when I open the game and i reach the part where the music should sound, it crash with that error.
 
Last edited:

gigan

Engaged Member
Modder
Nov 7, 2017
3,117
7,846
what is written in the line 1217 of the 0.9.rpy file? for me it looks like that you have forgoten there writtem the play music command.The error shows that there is only written play "audio/tension.mp3" instead play music "audio/tension.mp3"
 
  • Like
Reactions: rokit6/Naxoll

rokit6/Naxoll

Member
Mar 30, 2019
215
203
what is written in the line 1217 of the 0.9.rpy file? for me it looks like that you have forgoten there writtem the play music command.The error shows that there is only written play "audio/tension.mp3" instead play music "audio/tension.mp3"
In the line 1217 I have this code: play music "audio/tension.mp3"

1650310260172.png
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,561
2,183
I'm struggling now, because the error you originally posted kinda made sense. But you've edited the original post's quoted error message - and now it has me scratching my head too.

What's the game you are trying to correct? Perhaps looking at the original code will help guide our answers.

Also... sometimes, it's the lines before or after that are actually causing the problem. I don't see that being likely, but occasionally it happens.

Could you perhaps copy/paste lines 1212 to 1222 (or any range +/- 5 lines either side) here.
You can use [code=python] [/code] forum tags to show things or use the "...v" on the forum editor menu bar and select "</> Code". Sometimes context matters.
 
  • Like
Reactions: rokit6/Naxoll

gigan

Engaged Member
Modder
Nov 7, 2017
3,117
7,846
i found something on a other site but the post is from 2014 so i´m not sure.There was written " Rename the file, script is read from the files in order of their names. Your file is simply read before play statement is defined. " maybe that is the problem here too
 
  • Like
Reactions: rokit6/Naxoll

rokit6/Naxoll

Member
Mar 30, 2019
215
203
I'm struggling now, because the error you originally posted kinda made sense. But you've edited the original post's quoted error message - and now it has me scratching my head too.

What's the game you are trying to correct? Perhaps looking at the original code will help guide our answers.

Also... sometimes, it's the lines before or after that are actually causing the problem. I don't see that being likely, but occasionally it happens.

Could you perhaps copy/paste lines 1212 to 1222 (or any range +/- 5 lines either side) here.
You can use [code=python] [/code] forum tags to show things or use the "...v" on the forum editor menu bar and select "</> Code". Sometimes context matters.
Yes I edited the OP because i realize i copied the error when i tried to use only the "play" command.

The game im trying to correct is Girlfriend Tapes by BootyProfessor.

Here you have the lines above and below the play music "audio/tension.mp3"

Code:
    scene black with dissolve
    mc "A-ah...I'm sh...*hic*...shorry..."
    m "..."
    m "{size=-15}Yeah...me too.{/size}"
    scene hourslater with fade
    scene black with dissolve
    play music "audio/tension.mp3"
    "*slap*"
    "mmmmmgghh...haaaahwwwh...mmhhhmmmm..."
    mc "..."
    "*smack*"
    mc "(Ha?)"
 

rokit6/Naxoll

Member
Mar 30, 2019
215
203
i found something on a other site but the post is from 2014 so i´m not sure.There was written " Rename the file, script is read from the files in order of their names. Your file is simply read before play statement is defined. " maybe that is the problem here too
I also read that post but idk what the post refers to... Rename the .rpy or rename the sound file?
 

gigan

Engaged Member
Modder
Nov 7, 2017
3,117
7,846
I also read that post but idk what the post refers to... Rename the .rpy or rename the sound file?
the rpy file.Rename the rpyc file too.it might be enough if you write z_ in front of it.but in the next update you will have the same problem again.When the dev used then the 0.9.rpy file
 
  • Like
Reactions: rokit6/Naxoll

rokit6/Naxoll

Member
Mar 30, 2019
215
203
the rpy file.Rename the rpyc file too.it might be enough if you write z_ in front of it.but in the next update you will have the same problem again.When the dev used then the 0.9.rpy file
I tried that, i renamed the 0.9.rpy to z_0.9.rpy, the same with the .rpyc.


And I had this error when i reach the part when the music should sound:

I'm sorry, but an uncaught exception occurred.

While running game code:
Exception: Sayer 'play' is not defined.

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

Full traceback:
File "game/z_0.9.rpyc", line 1217, in script
<�K�,m���@�����M�%��V/�
File "renpy/ast.py", line 680, in execute
who = eval_who(self.who, self.who_fast)
File "renpy/ast.py", line 574, in eval_who
raise Exception("Sayer '%s' is not defined." % who)
Exception: Sayer 'play' is not defined.

I used the play music "audio/tension.mp3"
 

rokit6/Naxoll

Member
Mar 30, 2019
215
203
Can you try deleting the .rpyc file and then start the game? It should generate another one.
I tried it and now i can't even load any save game. It gives me this error:

I'm sorry, but an uncaught exception occurred.

While running game code:
File "renpy/common/00action_file.rpy", line 452, in __call__
renpy.load(fn)
Exception: Couldn't find a place to stop rolling back. Perhaps the script changed in an incompatible way?

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

Full traceback:
File "renpy/common/_layout/screen_load_save.rpym", line 35, in script
$ ui.interact()
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 "renpy/common/_layout/screen_load_save.rpym", line 35, in <module>
$ ui.interact()
File "renpy/ui.py", line 298, in interact
rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
File "renpy/display/core.py", line 3213, 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 4037, in interact_core
rv = root_widget.event(ev, x, y, 0)
File "renpy/display/layout.py", line 1059, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "renpy/display/transition.py", line 48, in event
return self.new_widget.event(ev, x, y, st) # E1101
File "renpy/display/layout.py", line 1059, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "renpy/display/layout.py", line 1059, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "renpy/display/screen.py", line 720, in event
rv = self.child.event(ev, x, y, st)
File "renpy/display/layout.py", line 1059, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "renpy/display/layout.py", line 1249, in event
rv = super(Window, self).event(ev, x, y, st)
File "renpy/display/layout.py", line 245, in event
rv = d.event(ev, x - xo, y - yo, st)
File "renpy/display/layout.py", line 1059, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "renpy/display/layout.py", line 1059, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "renpy/display/behavior.py", line 979, in event
return handle_click(self.clicked)
File "renpy/display/behavior.py", line 914, in handle_click
rv = run(action)
File "renpy/display/behavior.py", line 322, in run
new_rv = run(i, *args, **kwargs)
File "renpy/display/behavior.py", line 329, in run
return action(*args, **kwargs)
File "renpy/common/00action_file.rpy", line 452, in __call__
renpy.load(fn)
File "renpy/loadsave.py", line 769, in load
log.unfreeze(roots, label="_after_load")
File "renpy/python.py", line 2173, in unfreeze
self.rollback(0, force=True, label=label, greedy=greedy, on_load=True)
File "renpy/python.py", line 2005, in rollback
self.load_failed()
File "renpy/python.py", line 1923, in load_failed
raise Exception("Couldn't find a place to stop rolling back. Perhaps the script changed in an incompatible way?")
Exception: Couldn't find a place to stop rolling back. Perhaps the script changed in an incompatible way?
I made a copy of the old rpyc in case something like this could happen hahaha
 

AzureSheep

Newbie
Nov 5, 2017
73
1,718
You didn't delete all of the .rpyc files? I was talking about "0.9.rpyc". I see that you posted the game a few post back but I'll take a look at the code in a sec.
 
  • Like
Reactions: rokit6/Naxoll

rokit6/Naxoll

Member
Mar 30, 2019
215
203
You didn't delete all of the .rpyc files? I was talking about "0.9.rpyc". I see that you posted the game a few post back but I'll take a look at the code in a sec.
I only deleted the 0.9.rpyc and when i try to load any savegame it shows that error I post before
 

AzureSheep

Newbie
Nov 5, 2017
73
1,718
Copy and paste the code into a new .rpy file. Delete the old 0.9.rpy. I'm not sure why but that fixed the issue since it plays the music files now.

Edit: Its actually is the 0 at the start of the filename that is causing the issue. You can rename it to something like 'update_0.9.rpy'. Make sure you delete the .rpyc though.
 
  • Like
Reactions: rokit6/Naxoll

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,561
2,183
Okay.

Firstly. Never delete .rpyc unless you are also deliberately deleting the .rpy.

The RPYC file is what RenPy actually runs. It contains a very complex cross reference of each line of code in your script. Each line is "numbered" according to previous versions of your code. If you delete the RPYC file, everything is renumbered and so the next time the script runs, it loses all its known reference points. Save files no longer match the structure of the new version of the RPYC file.

Thankfully old copies of an RPYC file can repair things. But any "new" code (when compared with the old RPYC file) will be renumbered. So newer saves may not work

By renaming RPY files, it creates a new RPYC file to match. So you potentially have 2+ copies of the same code. RenPy allows this and has rules about which copy to run.

One potential reason for your play error MIGHT be that you're running a broken version of the code from a "wrong" RPYC file.

Try changing some text near that line and see if you see that update when that line is displayed. If not, you may have a mismatching RPYC file hanging around.
It's rare. But only because most devs never rename RPY files.
 

rokit6/Naxoll

Member
Mar 30, 2019
215
203
Copy and paste the code into a new .rpy file. Delete the old 0.9.rpy. I'm not sure why but that fixed the issue since it plays the music files now.

Edit: Its actually is the 0 at the start of the filename that is causing the issue. You can rename it to something like 'update_0.9.rpy'. Make sure you delete the .rpyc though.
Did you try it? Should I delete the rpyc aswell?

I deleted the original 0.9.rpy and i made another .rpy with the same name (0.9.rpy) and the same code. and it shows the same error:

I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/0.9.rpy", line 1217, in script
play music "audio/tension.mp3"
Exception: Sayer 'play' is not defined.

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

Full traceback:
File "game/0.9.rpy", line 1217, in script
play music "audio/tension.mp3"
File "renpy/ast.py", line 680, in execute
who = eval_who(self.who, self.who_fast)
File "renpy/ast.py", line 574, in eval_who
raise Exception("Sayer '%s' is not defined." % who)
Exception: Sayer 'play' is not defined.
I will attach the savefile where im trying to add the music.