How do you call a function in a regular renpy label script?

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
Jezzy
Regular
Posts: 30
Joined: Wed Jun 21, 2017 2:18 pm
Contact:

How do you call a function in a regular renpy label script?

#1 Post by Jezzy » Tue Jul 11, 2017 9:22 pm

Hi!

Its probably a very noob question but, I have a very simple function located in its own file that looks like this :

File ambiance sfx manager.rpy

Code: Select all

init python:
    def AmbianceManSFX():

        renpy.play("sfx/ambiance light city.ogg", "ambiance")

I want to call this function in the middle of a label of my choice. I know I could (theorically) call that function using this syntax :

Code: Select all

label start :
    $ AmbianceManSFX()
Its not working. I tried to put, for testing purpose, AmbianceManSFX() inside the screen.rpy file (in the screen say) and it works on every says.

Is there something I'm not getting right about calling a function in Renpy?

User avatar
Milkymalk
Miko-Class Veteran
Posts: 752
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: How do you call a function in a regular renpy label scri

#2 Post by Milkymalk » Tue Jul 11, 2017 11:08 pm

Unless your soundfile is silent, it should work.

Did you register your channel first?
https://www.renpy.org/doc/html/audio.ht ... er_channel
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

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

Re: How do you call a function in a regular renpy label scri

#3 Post by Alex » Wed Jul 12, 2017 12:25 pm

Also, try renpy.music.play with if_changed parameter
https://www.renpy.org/doc/html/audio.ht ... music.play

And you can use all the screen-language functions (just add a pair of extra brackets at the end)

Code: Select all

$ Play("ambiance", "sfx/ambiance light city.ogg")()
https://www.renpy.org/doc/html/screen_a ... io-actions

Post Reply

Who is online

Users browsing this forum: Google [Bot]