Variable sounds

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
bokuman
Regular
Posts: 65
Joined: Tue May 23, 2017 1:08 pm
Projects: VN 789
Deviantart: bokuman
Contact:

Variable sounds

#1 Post by bokuman »

I was using this thing to call a sound list, but i want add a variable name to change the character when is necesary.

Code: Select all

play sound cam_albedo
i tried this

Code: Select all

play sound ("cam_{}".format(waifu_name_dir))
but i received a message error: cam_albedo file is not found.

Any help is welcome, thanks in advance!

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Variable sounds

#2 Post by Alex »

You could do it like

Code: Select all

default cam_albedo = 'Pickup_Coin.ogg'
default waifu_name_dir = 'albedo'

init python:
    def sound_var(last_part, first_part='cam_'):
        var_name = first_part + last_part
        if hasattr(store, var_name):
            return getattr(store, var_name)
        else:
            return None
            
# The game starts here.
label start:
    "..."
    play sound sound_var(waifu_name_dir)
    "... ..."
    $ waifu_name_dir = '???'
    play sound sound_var(waifu_name_dir)
    "?!"
All the variables you've made are the fields of a 'store' object, so you can operate them.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]