Sound effect while typing?

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
bloobeary
Regular
Posts: 36
Joined: Fri Oct 04, 2019 3:02 pm
Deviantart: bloobeary
Soundcloud: user-212448702
Contact:

Re: Sound effect while typing?

#16 Post by bloobeary »

This is the code that I'm using for player character entry:

Code: Select all

    python:
        name = renpy.input(_("Type in your first name:"))

        name = name.strip() or __("Player")
I don't remember where I got it from, but after looking at: https://www.renpy.org/doc/html/screens.html#input
...and seeing that their example is:

Code: Select all

screen input_screen():
    window:
        has vbox

        text "Enter your name."
        input default "Joseph P. Blow, ESQ."
I'm now wondering if I'm using the wrong type of code to allow for the use of "changed" ...?

bloobeary
Regular
Posts: 36
Joined: Fri Oct 04, 2019 3:02 pm
Deviantart: bloobeary
Soundcloud: user-212448702
Contact:

Re: Sound effect while typing?

#17 Post by bloobeary »

Oookay, here's the latest update on my efforts to make this work...

I was advised by someone over on reddit to do this:

In the screens.rpy, In the input screen section, the line

Code: Select all

input id "input"
was altered to:

Code: Select all

input id "input" changed Typing
and then, in the script.rpy, I created this bit of python 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")
That got the typing sounds working, but... the Enter key no longer worked.

After consulting the rest of the code in this current forum thread, I cobbled together this:

Code: Select all

init python:
    def Typing(what):
        if renpy.display.interface.last_event.__dict__.get("key", None) == 8:
            renpy.jump("nametyped")
        else:
            renpy.music.play(renpy.random.choice(['sounds/typing1.wav','sounds/typing2.wav','sounds/typing3.wav']), channel="audio")
This.. ALMOST works.

Two important points:
8 is the integer for the backspace key. I put it there for testing purposes because I don't know the one for the return key.

after the renpy.jump advances to the nametyped label, the project crashes at the first line of character dialog it encounters.

Code: Select all

[code]
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 255, in script
    x "Dialogue goes here."

KeyError: u'name'

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

Full traceback:
  File "game/script.rpy", line 255, in script
    x "Dialogue goes here."
  File "renpy/ast.py", line 716, in execute
    renpy.exports.say(who, what, *args, **kwargs)
  File "renpy/exports.py", line 1417, in say
    who(what, *args, **kwargs)
  File "renpy/character.py", line 1208, in __call__
    who = self.prefix_suffix("who", self.who_prefix, who, self.who_suffix)
  File "renpy/character.py", line 1129, in prefix_suffix
    return (sub(prefix) + sub(body) + sub(suffix))
  File "renpy/character.py", line 1109, in sub
    return renpy.substitutions.substitute(s, scope=scope, force=force, translate=translate)[0]
  File "renpy/substitutions.py", line 270, in substitute
    s = formatter.vformat(s, (), kwargs)
  File "/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python2.7/string.py", line 563, in vformat
  File "/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python2.7/string.py", line 585, in _vformat
  File "/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python2.7/string.py", line 646, in get_field
  File "/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python2.7/string.py", line 605, in get_value
KeyError: u'name'

Windows-7-6.1.7601-SP1
Ren'Py 7.4.8.1895
Zero Day 1.0
Sat Oct 16 02:41:39 2021
So close, and yet so far.

bloobeary
Regular
Posts: 36
Joined: Fri Oct 04, 2019 3:02 pm
Deviantart: bloobeary
Soundcloud: user-212448702
Contact:

Re: Sound effect while typing?

#18 Post by bloobeary »

I have found a solution, and it is detailed here:
viewtopic.php?f=8&t=63344

...because i didn't create this thread so I can't mark it solved.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Sound effect while typing?

#19 Post by namastaii »

Hey @bloobeary, sorry I didn't see this. If you still want, I can send you an example of something I have in one of my project that works for me. Let me know!

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Sound effect while typing?

#20 Post by namastaii »

I'll just put my process here in case you're interested and want a variety of solutions. I tend to make my text input buttons.

This isn't a simplified example - just pasted directly from my project

Variable:

Code: Select all

default firstname = ""
Python block:
(this uses a sound effect for writing and erasing)

Code: Select all

def name_func(newstring):
        store.firstname = newstring
        if renpy.display.interface.last_event.__dict__.get("key",None) == 8:
            renpy.music.play(renpy.random.choice(['sounds/erase1.ogg','sounds/erase2.ogg','sounds/erase3.ogg']), channel="audio")
        else:
            renpy.sound.play(renpy.random.choice(['sounds/writing2.ogg','sounds/writing3.ogg','sounds/writing4.ogg']), channel="audio")
In my screen:

Code: Select all

input default firstname pos(130,300) changed name_func length 10 font "fonts/Kristi.ttf" color "#696969" size 60 style "newstudent_button"

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]