[SOLVED] Play the voice's MC based on their gender using Renpy's Automatic Voice function.

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
User avatar
alexei
Regular
Posts: 137
Joined: Mon Sep 09, 2019 10:31 am
Completed: re:shape, Monster Boys Doctor, Hearts and Hexes, The Prince's Heart, Dragon Gazer
Projects: Motifs, Longing for Change, The Sinking of the Dream Chaser, Town of the Damned, Monster Boy Wars
Organization: Funigami
itch: funigami
Discord: alexei#5190
Contact:

Re: Play voice's MC based on their gender.

#16 Post by alexei » Fri Jul 22, 2022 11:55 am

I'll check out everything tonight and see what works! Thanks for your help, guys.

User avatar
alexei
Regular
Posts: 137
Joined: Mon Sep 09, 2019 10:31 am
Completed: re:shape, Monster Boys Doctor, Hearts and Hexes, The Prince's Heart, Dragon Gazer
Projects: Motifs, Longing for Change, The Sinking of the Dream Chaser, Town of the Damned, Monster Boy Wars
Organization: Funigami
itch: funigami
Discord: alexei#5190
Contact:

Re: Play voice's MC based on their gender.

#17 Post by alexei » Mon Jul 25, 2022 5:07 am

Ok peeps,

I tested both and it seems that what Alouette suggested initially works perfectly fine!

Code: Select all

define mc = Character("Main Character", voice_tag="mc_voice")
default gender = "female" # or "male"

init python:
    def genderVoice(id):
        global gender
        voice_tag = _voice.tag
        if voice_tag == "mc_voice":
            return "voice/{}/{}.ogg".format(gender, id)
        return "voice/{}.ogg".format(id)
        
    config.auto_voice = genderVoice
The Callback function doesn't work, the following exception occurs.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/assets.rpy", line 2, in script
    define y = Character("You", callback=genderVoice)
  File "game/assets.rpy", line 2, in script
    define y = Character("You", callback=genderVoice)
  File "game/assets.rpy", line 2, in <module>
    define y = Character("You", callback=genderVoice)
NameError: name 'genderVoice' is not defined

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

Full traceback:
  File "renpy/bootstrap.py", line 274, in bootstrap
    renpy.main.main()
  File "renpy/main.py", line 558, in main
    renpy.game.context().run(node)
  File "game/assets.rpy", line 2, in script
    define y = Character("You", callback=genderVoice)
  File "game/assets.rpy", line 2, in script
    define y = Character("You", callback=genderVoice)
  File "renpy/ast.py", line 2441, in execute
    self.set()
  File "renpy/ast.py", line 2455, in set
    value = renpy.python.py_eval_bytecode(self.code.bytecode)
  File "renpy/python.py", line 1073, in py_eval_bytecode
    return eval(bytecode, globals, locals)
  File "game/assets.rpy", line 2, in <module>
    define y = Character("You", callback=genderVoice)
NameError: name 'genderVoice' is not defined

Windows-10-10.0.19041 AMD64
Ren'Py 7.5.1.22070801
ReShape 0.93
Mon Jul 25 12:02:24 2022
But I'm so glad that you helped me find a solution to this! I'll mark this as resolved, and I hope future programmers find it useful!

Post Reply

Who is online

Users browsing this forum: No registered users