Hello is there a way to add sounds to ticking timer?

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
newbneet
Newbie
Posts: 4
Joined: Sun Nov 19, 2023 10:58 pm
Contact:

Hello is there a way to add sounds to ticking timer?

#1 Post by newbneet »

Hi there, I'm making a warioware styled game and so far so good, I've managed to display images along timer countdown using showif statements, but having trouble with adding sounds to the timer.

So basically I'm using the default renpy timer that utilizes screens, and I want to play a sound each time the timer ticks, sort of like a beeping sound for a ticking time bomb. Another problem is I want the sound to change the closer the timer are to zero, so I wish to have complete control of what sound is played for each second.

Is there anyone that can help me? If anyone can help me please let me know, thank you!

Also my image countdown is very crude (shown below) and I need to basically set each image into each seconds, if anyone knows how to make it more optimized please let me know, thank you!

Code: Select all

showif seconds == 1:

   add "count1.png" at center

elif seconds == 0:

   add "count0.png" at center

User avatar
m_from_space
Miko-Class Veteran
Posts: 949
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Hello is there a way to add sounds to ticking timer?

#2 Post by m_from_space »

You don't need showif if you don't use any events inside an ATL transform that's part of the image.

Some countdown screen, I hope it helps understanding what you want.

Code: Select all

screen countdown(s):
    default seconds = s
    if seconds == 0:
        text "BOOM!" at center
        timer 1.0 action Hide()
    else:
        text "[seconds] seconds left" at center
        if seconds < 5:
            # I recommend using the "audio" channel inside the Play() function to play it in parallel with other audio stuff
            timer 1.0 action [ SetScreenVariable("seconds", seconds - 1), Play("audio", "audio/beepbeepbeep.ogg") ] repeat True
        else:
            timer 1.0 action [ SetScreenVariable("seconds", seconds - 1), Play("audio", "audio/beep.ogg") ] repeat True

label start:
    show screen countdown(60)
    "Fin."

newbneet
Newbie
Posts: 4
Joined: Sun Nov 19, 2023 10:58 pm
Contact:

Re: Hello is there a way to add sounds to ticking timer?

#3 Post by newbneet »

@m_from_space

hi! sorry I haven't turned on the notification so I didn't realize you replied!

Thank you for your help! I haven't tried it yet but will do as soon as I can and I'll report back, thank you!

newbneet
Newbie
Posts: 4
Joined: Sun Nov 19, 2023 10:58 pm
Contact:

Re: Hello is there a way to add sounds to ticking timer?

#4 Post by newbneet »

m_from_space wrote: Mon Nov 20, 2023 10:13 am You don't need showif if you don't use any events inside an ATL transform that's part of the image.

Some countdown screen, I hope it helps understanding what you want.

Code: Select all

screen countdown(s):
    default seconds = s
    if seconds == 0:
        text "BOOM!" at center
        timer 1.0 action Hide()
    else:
        text "[seconds] seconds left" at center
        if seconds < 5:
            # I recommend using the "audio" channel inside the Play() function to play it in parallel with other audio stuff
            timer 1.0 action [ SetScreenVariable("seconds", seconds - 1), Play("audio", "audio/beepbeepbeep.ogg") ] repeat True
        else:
            timer 1.0 action [ SetScreenVariable("seconds", seconds - 1), Play("audio", "audio/beep.ogg") ] repeat True

label start:
    show screen countdown(60)
    "Fin."
Hi I've tested it and it works perfectly thank you!

But I still have a question though, for images, did you mean that I need to code the seconds into the ATL? As in, adding pause for each seconds to display each images?
Or the only other way I can think of is writing if conditional for each seconds which also sounds tedious hahaha.

User avatar
m_from_space
Miko-Class Veteran
Posts: 949
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Hello is there a way to add sounds to ticking timer?

#5 Post by m_from_space »

newbneet wrote: Thu Nov 23, 2023 5:46 am But I still have a question though, for images, did you mean that I need to code the seconds into the ATL? As in, adding pause for each seconds to display each images?
Or the only other way I can think of is writing if conditional for each seconds which also sounds tedious hahaha.
You don't need any conditional logic. If you want to show different images (or text etc.) depending on the seconds (or any other variable), you can do this:

Code: Select all

# renpy format
add "count[seconds].png"

# python 3+
add f"count{seconds}.png"

# python 2+
add "count{}.png".format(seconds)

newbneet
Newbie
Posts: 4
Joined: Sun Nov 19, 2023 10:58 pm
Contact:

Re: Hello is there a way to add sounds to ticking timer?

#6 Post by newbneet »

Wow that's really cool! Funny thing is I already made an ATL and brute forced my way lol but this will certainly help, thanks a lot!

Also just to confirm that all those 3 codes you posted are the same and does the same thing right?

User avatar
m_from_space
Miko-Class Veteran
Posts: 949
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Hello is there a way to add sounds to ticking timer?

#7 Post by m_from_space »

newbneet wrote: Thu Nov 23, 2023 8:38 am Also just to confirm that all those 3 codes you posted are the same and does the same thing right?
Basically yes, but internally those are executed differently. The Renpy format does not work outside of Renpy script language of course. The other two are Python options, meaning they also work in normal python code.

Post Reply

Who is online

Users browsing this forum: Google [Bot]