CREATE YOUR AI CUM SLUT ON CANDY.AI TRY FOR FREE
x

Ren'Py [Solved]small sound problem

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,131
3,195
i have a screen when I press key it play the sound when it only should play when ryan_lust2 reached 100 but plays when pressing the up and down keys

Python:
screen masturbation_move():
    if masturbation_move < 30:
        key 'repeat_K_UP':
            action SetVariable('masturbation_move', masturbation_move + 1)
        key 'K_UP':
            action SetVariable('ryan_lust2', ryan_lust2 + 5)
    if masturbation_move > 0:
        key 'repeat_K_DOWN':
            action SetVariable('masturbation_move', masturbation_move - 1)
        key 'K_DOWN':
            action SetVariable('ryan_lust2', ryan_lust2 + 5)

  images code not included

    if ryan_lust2 == 100:
        $ renpy.music.play("SWFLongScream2.wav", loop = False)
        add "images/masturbation/masturbation_cum.png"
        timer 2.0 action Hide("masturbation_move"), Call("ryanlustreset2")
 

Turning Tricks

Rendering Fantasies
Game Developer
Apr 9, 2022
1,355
2,523
Without the code that calls this screen, it's hard to say, but even my limited experience with Ren'py and Python can see a few areas of concern...

First, you have a variable with the same name as your screen label (masturbation_move). Not sure if that's causing any problems but it seems like a poor choice.

Second, and this is without seeing the rest of the code, but both those if statements will be valid if masturbation_move is less than 30, so pushing the up arrow and the down arrow with both raise ryan_lust2 by 5 points. Again, without the context, I don't know if that was your intent.

Next, why use the python equivalent of music.play when Ren'py has a perfectly fine function itself with pre-defined channels?

play sound ""SWFLongScream2.wav" noloop is the same as what you used.

Finally, the action to hide the screen masturbation_move should have square brackets around it, when you have multiple actions on a single interaction.

timer 2.0 action [Hide("masturbation_move"), Call("ryanlustreset2")]

It's possible that when ryan_lust2 reaches 100, only the Hide("masturbation_move") part of your action is happening, and not the Call to reset. In that case, the variable just keeps going and every keystroke triggers the sound.

You can also use the Data action SetVariable to control your variable loop, instead of an IF block.

... like maybe change

Python:
    if masturbation_move < 30:
        key 'repeat_K_UP':
            action SetVariable('masturbation_move', masturbation_move + 1)
with this...


Python:
    key 'repeat_K_UP':
        action SetVariable("masturbation_move", If(masturbation_move < 30, masturbation_move + 1, 30))
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,131
3,195
Without the code that calls this screen, it's hard to say, but even my limited experience with Ren'py and Python can see a few areas of concern...

First, you have a variable with the same name as your screen label (masturbation_move). Not sure if that's causing any problems but it seems like a poor choice.

Second, and this is without seeing the rest of the code, but both those if statements will be valid if masturbation_move is less than 30, so pushing the up arrow and the down arrow with both raise ryan_lust2 by 5 points. Again, without the context, I don't know if that was your intent.

Next, why use the python equivalent of music.play when Ren'py has a perfectly fine function itself with pre-defined channels?

play sound ""SWFLongScream2.wav" noloop is the same as what you used.

Finally, the action to hide the screen masturbation_move should have square brackets around it, when you have multiple actions on a single interaction.

timer 2.0 action [Hide("masturbation_move"), Call("ryanlustreset2")]

It's possible that when ryan_lust2 reaches 100, only the Hide("masturbation_move") part of your action is happening, and not the Call to reset. In that case, the variable just keeps going and every keystroke triggers the sound.

You can also use the Data action SetVariable to control your variable loop, instead of an IF block.

... like maybe change

Python:
    if masturbation_move < 30:
        key 'repeat_K_UP':
            action SetVariable('masturbation_move', masturbation_move + 1)
with this...


Code:
    key 'repeat_K_UP':
        action SetVariable("masturbation_move", If(masturbation_move < 30, masturbation_move + 1, 30))
this is the code
Python:
if ryan_lust2 == 100:
        $ renpy.music.play("SWFLongScream2.wav", loop = False) <------ this play when the keys are press
        add "images/masturbation/masturbation_cum.png"
        timer 2.0 action Hide("masturbation_move"), Call("ryanlustreset2")
the rest the code works fine
 

Turning Tricks

Rendering Fantasies
Game Developer
Apr 9, 2022
1,355
2,523
this is the code
Python:
if ryan_lust2 == 100:
        $ renpy.music.play("SWFLongScream2.wav", loop = False) <------ this play when the keys are press
        add "images/masturbation/masturbation_cum.png"
        timer 2.0 action Hide("masturbation_move"), Call("ryanlustreset2")
the rest the code works fine

That's the code that closes that screen, not the one that calls or shows it. What I was referring too was what is the value of ryan_lust2 when you actually call that masturbation_move screen? When you get the sound on a key press, have you opened the dev console and checked what the value is for ryan_lust2? Is it under 100?
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,131
3,195
you still don't understand what I'm saying

when I pressing the up/down keys the sound plays while pressing the keys when it shouldn't
it should after the ryanlust2 hits 100
 
Last edited:

Turning Tricks

Rendering Fantasies
Game Developer
Apr 9, 2022
1,355
2,523
you still don't understand what I'm saying

when I pressing the up/down keys the sound plays while pressing the keys when it shouldn't
it should after the ryanlust2 hits 100
And that is why I am asking if you have actually looked at that variable and made sure it wasn't at 100 already. What is the value of ryan_lust2 when you hear the sound?

I see you have a call to reset that variable, but I am wondering if that is not being actioned because the syntax of that line is incorrect (no square brackets around the multiple actions). So maybe your variable is climbing when you think it should be reset. Without the rest of the code for this, it's impossible to say.

You also have no limits set on that variable to keep it from going over 100 (in what you have shown so far) so it's quite likely that you can have situation where you never get the sound at all, because the variable never reaches exactly 100. For example, you hit up or down arrow once and increase the variable by 5, but if you hold the up key, it increases in increments of 1, so what happens if you are at 98 (for example) and then hit up arrow again? The variable is now 104 and that whole IF statement is useless, since it's looking for an exact value of 100.
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,131
3,195
Can you share?
I put it in a new screen and call it

Python:
screen masturbation_move():
    use masturbation_move_image
    if masturbation_move < 30:
        key 'repeat_K_UP':
            action SetVariable('masturbation_move', masturbation_move + 1)
        key 'K_UP':
            action SetVariable('ryan_lust2', ryan_lust2 + 5)
    if masturbation_move > 0:
        key 'repeat_K_DOWN':
            action SetVariable('masturbation_move', masturbation_move - 1)
        key 'K_DOWN':
            action SetVariable('ryan_lust2', ryan_lust2 + 5)

screen masturbation_move_image():

    if masturbation_move == 0:
        add "images/masturbation/masturbation_00.png"
    if masturbation_move == 1:
        add "images/masturbation/masturbation_01.png"
    if masturbation_move == 2:
        add "images/masturbation/masturbation_02.png"
    if masturbation_move == 3:
        add "images/masturbation/masturbation_03.png"
    if masturbation_move == 4:
        add "images/masturbation/masturbation_04.png"
    if masturbation_move == 5:
        add "images/masturbation/masturbation_05.png"
    if masturbation_move == 6:
        add "images/masturbation/masturbation_06.png"
    if masturbation_move == 7:
        add "images/masturbation/masturbation_07.png"
    if masturbation_move == 8:
        add "images/masturbation/masturbation_08.png"
    if masturbation_move == 9:
        add "images/masturbation/masturbation_09.png"
    if masturbation_move == 10:
        add "images/masturbation/masturbation_10.png"
    if masturbation_move == 11:
        add "images/masturbation/masturbation_11.png"
    if masturbation_move == 12:
        add "images/masturbation/masturbation_12.png"
    if masturbation_move == 13:
        add "images/masturbation/masturbation_13.png"
    if masturbation_move == 14:
        add "images/masturbation/masturbation_14.png"
    if masturbation_move == 15:
        add "images/masturbation/masturbation_15.png"
    if masturbation_move == 16:
        add "images/masturbation/masturbation_16.png"
    if masturbation_move == 17:
        add "images/masturbation/masturbation_17.png"
    if masturbation_move == 18:
        add "images/masturbation/masturbation_18.png"
    if masturbation_move == 19:
        add "images/masturbation/masturbation_19.png"
    if masturbation_move == 20:
        add "images/masturbation/masturbation_20.png"
    if masturbation_move == 21:
        add "images/masturbation/masturbation_21.png"
    if masturbation_move == 22:
        add "images/masturbation/masturbation_22.png"
    if masturbation_move == 23:
        add "images/masturbation/masturbation_23.png"
    if masturbation_move == 24:
        add "images/masturbation/masturbation_24.png"
    if masturbation_move == 25:
        add "images/masturbation/masturbation_25.png"
    if masturbation_move == 26:
        add "images/masturbation/masturbation_26.png"
    if masturbation_move == 27:
        add "images/masturbation/masturbation_27.png"
    if masturbation_move == 28:
        add "images/masturbation/masturbation_28.png"
    if masturbation_move == 29:
        add "images/masturbation/masturbation_29.png"
    if masturbation_move == 30:
        add "images/masturbation/masturbation_30.png"

    if ryan_lust2 == 100:
        timer 2.1 action Hide("masturbation_move"), Show("ryan_cum")

screen ryan_cum():
    if ryan_lust2 == 100:
        $ renpy.music.play("SWFLongScream2.wav", loop = False)
        add "images/masturbation/masturbation_cum.png"           
        timer 2.0 action Hide("masturbation_move"), Call("ryanlustreset2")
 
Last edited:

peterppp

Active Member
Mar 5, 2020
769
1,359
weird. i did some testing and as soon as any action is triggered in the screen, any "$ renpy" command behind an if statement is executed regardless of if the if statement is true or not.

seems like a bug to me or there is something with screens i dont know.
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,131
3,195
weird. i did some testing and as soon as any action is triggered in the screen, any "$ renpy" command behind an if statement is executed regardless of if the if statement is true or not.

seems like a bug to me or there is something with screens i dont know.
this has been solved
 

gojira667

Member
Sep 9, 2019
328
324
weird. i did some testing and as soon as any action is triggered in the screen, any "$ renpy" command behind an if statement is executed regardless of if the if statement is true or not.

seems like a bug to me or there is something with screens i dont know.
Probably . Part of why the Function action exists is so it doesn't run multiple times or at "unpredictable times".

:unsure: Aside from screen default statements you would want your function to be if you are calling it bare.

edit:
Also, Ren'Py has , .
 
Last edited:
  • Like
Reactions: peterppp

peterppp

Active Member
Mar 5, 2020
769
1,359
Also, Ren'Py has , .
but how to use an action without a button or similar? if i look it up online, people say to use the $renpy function of the action. guess that's why he used it
 

gojira667

Member
Sep 9, 2019
328
324
but how to use an action without a button or similar? if i look it up online, people say to use the $renpy function of the action. guess that's why he used it
:WaitWhat: You mean ? It's not what the OP used. He called the Python equivalent of play music. Using renpy.run wouldn't help either as the whole point is to immediately execute the action...

Staying away from custom, a ridiculously short duration timer behind the if. :unsure: If a bar is suitable then many of them have an action kwarg that runs after the value is updated (combine with If() action). A ui.adjustment() with a custom changed def might work too. Separate screen that uses the on event handler.
 
  • Like
Reactions: peterppp

peterppp

Active Member
Mar 5, 2020
769
1,359
:WaitWhat: You mean ? It's not what the OP used. He called the Python equivalent of play music.
that's what i meant lol. i was talking about the "play" action. not "action" in itself.
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,131
3,195
I put it in a new screen and call it

Python:
screen masturbation_move():
    use masturbation_move_image
    if masturbation_move < 30:
        key 'repeat_K_UP':
            action SetVariable('masturbation_move', masturbation_move + 1)
        key 'K_UP':
            action SetVariable('ryan_lust2', ryan_lust2 + 5)
    if masturbation_move > 0:
        key 'repeat_K_DOWN':
            action SetVariable('masturbation_move', masturbation_move - 1)
        key 'K_DOWN':
            action SetVariable('ryan_lust2', ryan_lust2 + 5)

screen masturbation_move_image():

    if masturbation_move == 0:
        add "images/masturbation/masturbation_00.png"
    if masturbation_move == 1:
        add "images/masturbation/masturbation_01.png"
    if masturbation_move == 2:
        add "images/masturbation/masturbation_02.png"
    if masturbation_move == 3:
        add "images/masturbation/masturbation_03.png"
    if masturbation_move == 4:
        add "images/masturbation/masturbation_04.png"
    if masturbation_move == 5:
        add "images/masturbation/masturbation_05.png"
    if masturbation_move == 6:
        add "images/masturbation/masturbation_06.png"
    if masturbation_move == 7:
        add "images/masturbation/masturbation_07.png"
    if masturbation_move == 8:
        add "images/masturbation/masturbation_08.png"
    if masturbation_move == 9:
        add "images/masturbation/masturbation_09.png"
    if masturbation_move == 10:
        add "images/masturbation/masturbation_10.png"
    if masturbation_move == 11:
        add "images/masturbation/masturbation_11.png"
    if masturbation_move == 12:
        add "images/masturbation/masturbation_12.png"
    if masturbation_move == 13:
        add "images/masturbation/masturbation_13.png"
    if masturbation_move == 14:
        add "images/masturbation/masturbation_14.png"
    if masturbation_move == 15:
        add "images/masturbation/masturbation_15.png"
    if masturbation_move == 16:
        add "images/masturbation/masturbation_16.png"
    if masturbation_move == 17:
        add "images/masturbation/masturbation_17.png"
    if masturbation_move == 18:
        add "images/masturbation/masturbation_18.png"
    if masturbation_move == 19:
        add "images/masturbation/masturbation_19.png"
    if masturbation_move == 20:
        add "images/masturbation/masturbation_20.png"
    if masturbation_move == 21:
        add "images/masturbation/masturbation_21.png"
    if masturbation_move == 22:
        add "images/masturbation/masturbation_22.png"
    if masturbation_move == 23:
        add "images/masturbation/masturbation_23.png"
    if masturbation_move == 24:
        add "images/masturbation/masturbation_24.png"
    if masturbation_move == 25:
        add "images/masturbation/masturbation_25.png"
    if masturbation_move == 26:
        add "images/masturbation/masturbation_26.png"
    if masturbation_move == 27:
        add "images/masturbation/masturbation_27.png"
    if masturbation_move == 28:
        add "images/masturbation/masturbation_28.png"
    if masturbation_move == 29:
        add "images/masturbation/masturbation_29.png"
    if masturbation_move == 30:
        add "images/masturbation/masturbation_30.png"

    if ryan_lust2 == 100:
        timer 2.1 action Hide("masturbation_move"), Show("ryan_cum")

screen ryan_cum():
    if ryan_lust2 == 100:
        $ renpy.music.play("SWFLongScream2.wav", loop = False)
        add "images/masturbation/masturbation_cum.png"         
        timer 2.0 action Hide("masturbation_move"), Call("ryanlustreset2")
is the a better way of doing this code like using a class and how to use it

something like this but I just can't remember how I did it
https://f95zone.to/threads/masturbation-movements-in-renpy.145258/