[SOLVED] Sound effect while typing
Posted: Sat Oct 16, 2021 4:02 am
Since I didn't create the original thread:
viewtopic.php?f=8&t=40217
... I'm going to create a new one here so that I can mark this problem as solved.
Here's the solution:
Add this bit of code before the label start:
typing1.wav through typing3.wav should be short single beeps or keypress sounds.
just below that add this bit of code:
Down in the dialogue section of the code, this is what I am using to generate the input event:
and finally, make this edit to the input section of the screens.rpy
Note that the only changes are in the last two lines, there.
Adding changed Typing calls the sound event.
and the key "K_RETURN" line makes the Enter key work.
Someone better at the code may find a more elegant solution, but for now, I have this and it works. So, here it is.
Many thanks and much credit to ShiroVN over on /r/Renpy
viewtopic.php?f=8&t=40217
... I'm going to create a new one here so that I can mark this problem as solved.
Here's the solution:
Add this bit of code before the label start:
Code: Select all
init python:
def Typing(what):
renpy.music.play(renpy.random.choice(['sounds/typing1.wav','sounds/typing2.wav','sounds/typing3.wav']), channel="audio")
just below that add this bit of code:
Code: Select all
init -2 python:
class GetInput(Action):
def __init__(self,screen_name,input_id):
self.screen_name=screen_name
self.input_id=input_id
def __call__(self):
if renpy.get_widget(self.screen_name,self.input_id):
return str(renpy.get_widget(self.screen_name,self.input_id).content)
Code: Select all
python:
name = renpy.input(_("Type in your first name:"))
name = name.strip() or __("Player")
Code: Select all
screen input(prompt):
style_prefix "input"
window:
vbox:
xalign gui.dialogue_text_xalign
xpos gui.dialogue_xpos
xsize gui.dialogue_width
ypos gui.dialogue_ypos
text prompt style "input_prompt"
input id "input" changed Typing
key "K_RETURN" action GetInput("input", "input")
Adding changed Typing calls the sound event.
and the key "K_RETURN" line makes the Enter key work.
Someone better at the code may find a more elegant solution, but for now, I have this and it works. So, here it is.
Many thanks and much credit to ShiroVN over on /r/Renpy