Ren'Py trying to get stamina and lust to work together

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,041
3,140
trying make a thing for renpy when you move your lust goes up to a point before he cums there 5 stages

trying use stamina with numbers instead of using true/false

so I want lust and stamina to work with each other

like if stamina is at 20 it's at stage 1 the lust goes by 25
if stamina is at 40 it's at stage 2 the lust goes by 20 and so on

hope you you understand what I'm trying to do the code that I show below it does work the way I want it to but only with stamina_true == True


STAGE 1​
STAGE 2​
STAGE 3​
STAGE 4​
STAGE 5​
cum1.png cum2.png cum3.png cum4.png cum5.png

here code

Python:
label start:
    $ Playing = True
    while Playing:   

        if clickType == "mapSelect":
            if stamina_true == True:
                if ryan.lust >= 0 and ryan.lust <= 76:
                    $ ryan.lust += 25
                    $ location = UIreturn
                elif ryan.lust == 100:
                    $ ryan.lust -= 100
                    $ stamina_true = False
                    $ stamina_true2 = True
                    $ location = UIreturn
            elif stamina_true2 == True:
                if ryan.lust >= 0 and ryan.lust <= 81:
                    $ ryan.lust += 20
                    $ location = UIreturn
                elif ryan.lust == 100:
                    $ ryan.lust -= 100
                    $ stamina_true2 = False
                    $ stamina_true3 = True
                    $ location = UIreturn
            elif stamina_true3 == True:
                if ryan.lust >= 0 and ryan.lust <= 91:
                    $ ryan.lust += 10
                    $ location = UIreturn
                elif ryan.lust == 100:
                    $ ryan.lust -= 100
                    $ stamina_true3 = False
                    $ stamina_true4 = True
                    $ location = UIreturn
            elif stamina_true4 == True:
                if ryan.lust >= 0 and ryan.lust <= 96:
                    $ ryan.lust += 5
                    $ location = UIreturn
                elif ryan.lust == 100:
                    $ ryan.lust -= 100
                    $ stamina_true4 = False
                    $ stamina_true5 = True
                    $ location = UIreturn
            elif stamina_true5 == True:
                if ryan.lust >= 0 and ryan.lust <= 99:
                    $ ryan.lust += 1
                    $ location = UIreturn
                elif ryan.lust == 100:
                    $ ryan.lust -= 100
                    $ stamina_true5 = False
                    $ stamina_true = True
                    $ location = UIreturn
        $ location = UIreturn
animation code
Python:
hbox:
        yalign 1.0
        xpos 750
        if stamina_true == True and ryan.lust == 100:
            $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
            add "dick1"

        if stamina_true2 == True and ryan.lust == 100:
            $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
            add "dick2"

        if stamina_true3 == True and ryan.lust == 100:
            $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
            add "dick3"

        if stamina_true4 == True and ryan.lust == 100:
            $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
            add "dick4"
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
If I'm reading that correctly, you want the lust to have diminishing returns. You seem to be counting from 0 to 100 each time for lust. When it reaches 100, it goes back down to zero and stamina increases, so next time it takes longer to reach 100.

I can see lots of ways to do this, so let me try to explain a couple of them.


First things first though... I'd suggest looking at this link, specifically the section about half way down titled "Python Comparison Operators". Though the stuff above it is probably relevant to you too. It lays out all your options.



Back to the code...

One way would be do do basic arithmetic against the stamina value, to convert it to a "stamina stage". Something like:

Python:
    $ stamina_stage = int(stamina / 20) + 1

    if stamina_stage == 1:
        $ lust += 25
    elif stamina_stage == 2:
        $ lust += 20
    elif stamina_stage == 3:
        $ lust += 10
    elif stamina_stage == 4:
        $ lust += 5
    else:
        $ lust += 1

    if lust >= 100:
        $ lust = 0
        $ stamina += 20

In this example, I'm dividing stamina by 20 and storing it in stamina_stage. I'm using int() to only store an integer number (not 1.5's or 0.76's), just whole, round numbers and not any decimal places. I'm adding 1 at the end, just so the numbers go from 1 to 5 rather than 0 to 4. RenPy tends to only do integer math anyway, I'm just being explicit about it to avoid all doubt.

The ranges would be 0-19 (1), 20-39 (2), 40-59 (3), etc.


Another way to code it would be do get rid of stamina_stage entirely and check for ranges

Python:
    if stamina >= 0 and stamina <= 20:
        $ lust += 25
    elif stamina >= 21 and stamina <= 40:
        $ lust += 20
    elif stamina >= 41 and stamina <= 60:
        $ lust += 10
    elif stamina >= 61 and stamina <= 80:
        $ lust += 5
    else:
        $ lust += 1

    if lust >= 100:
        $ lust = 0
        $ stamina += 20

This is more in line with your original post, where 20 is stage 1 rather than stage 2 (as with my first example, due to the way math works). This has more flexibility, since you could change things to use different ranges rather than stepping up in 20's all the time.

There's the potential for typing errors. Where you check for 41 thru 60, but accidently type 62 thru 80 for the next one. Should be pretty quick to spot though.


Finally, a variation on the previous example, but making use of the fact that elif can only be True once.

Python:
    if stamina < 21:
        $ lust += 25
    elif stamina < 41:
        $ lust += 20
    elif stamina < 61:
        $ lust += 10
    elif stamina < 81:
        $ lust += 5
    else:
        $ lust += 1

    if lust >= 100:
        $ lust = 0
        $ stamina += 20

This requires a little more understanding of how if, elif and else actually works. The basics though are that once it finds a condition it knows to be true, it stops looks for other alternatives. So while 55 is less than both 61 and 81, it would only trigger the elif stamina < 61: check, since that is coded first.

Realistically, the 2nd example I gave is the one that most new programmers would be most comfortable with - since it is probably the clearest about what is actually going on... even if it's more typing than actually necessary.

There is a way to write all this without using elif at all... and only using if statements, but it requires working backward through the stamina numbers (checking for >= 100 first and then going down for each following check... while also requiring a jump statement too. Honestly, it's probably unnecessary to explain in detail... as long as you are comfortable with how elif works.
 
  • Like
Reactions: rayminator and xj47

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,041
3,140
I have tried it that way before but it show double of the animation



it shows like this that why have it the way have it right now

101010.png
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
I will admit, I couldn't quite see how the second bit of your code was linked to the first, so I ignored it.

But reading your reply, wouldn't you just code it like:
(Using my 2nd example as a baseline for rewriting the screen code...

Python:
hbox:
    yalign 1.0
    xpos 750

    if ryan.lust == 100:
        if stamina >= 0 and stamina <= 20:
            $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
            add "dick1"
        elif stamina >= 21 and stamina <= 40:
            $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
            add "dick2"
        elif stamina >= 41 and stamina <= 60:
            $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
            add "dick3"
        elif stamina >= 61 and stamina <= 80:
            $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
            add "dick4"
        else:
            $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
            add "dick5"

The bit that is throwing me off is the insistence upon doing something when lust == 100 while at the same time resetting the value back down to zero when it reaches 100. It's unclear to me when the screen is displayed compared with when these numbers are being updated. So exactly what the value should/would be at the point the screen is shown is equally unclear to me.

It might need a bit of a tweak like:

Python:
    if lust > 100:
        lust = 0
        stamina += 20

Checking for values greater than 100 rather than doing a "greater than or equal to" check.
(actually, probably not... but I'll keep it here just in case I'm overthinking it and you see a potential I don't).


Alternatively... Maybe... ?...

Python:
    # [...]

    if lust >= 100:
        orgasm_needed = True
        lust = 0
        stamina += 20

Python:
hbox:
    yalign 1.0
    xpos 750

    if orgasm_needed == True:
        if stamina >= 0 and stamina <= 20:
            $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
            add "dick1"
        elif stamina >= 21 and stamina <= 40:
            $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
            add "dick2"
        elif stamina >= 41 and stamina <= 60:
            $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
            add "dick3"
        elif stamina >= 61 and stamina <= 80:
            $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
            add "dick4"
        else:
            $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
            add "dick5"
        $ orgasm_needed = False

Or some variation on that, using a flag to handle "getting to 100", while at the same time resetting the actual number back to 0.
 
  • Like
Reactions: rayminator

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,285
Python:
    $ stamina_stage = int(stamina / 20) + 1

    if stamina_stage == 1:
        $ lust += 25
    elif stamina_stage == 2:
        $ lust += 20
    elif stamina_stage == 3:
        $ lust += 10
    elif stamina_stage == 4:
        $ lust += 5
    else:
        $ lust += 1

    if lust >= 100:
        $ lust = 0
        $ stamina += 20
This version can be reduced:
Python:
define stamina_effect = [ 25, 20, 10, 5 ]

label whatever:
    $ stamina_stage = int(stamina / 20)
    # To not break the game if stamina goes over the limit, while not having
    # to have to limit its value.
    if stamina_stage < len( stamina_effect ):
        $ lust += stamina_effect[stamina_stage]
    else:
        $ lust += 1

    if lust >= 100:
        $ lust = 0
        $ stamina += 20
It have exactly the same effect, but since stamina_stage reduce the range to a single value, it permit this simplification.

This approach should also permit to simplify the screen itself:
Python:
define stamina_pict = [ "dick1", "dick2", "dick3", "dick4" ]

screen whatever:
    hbox:
        yalign 1.0
        xpos 750

        if ryan.lust == 100:
            $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
            if stamina_stage < len( stamina_pict ):
                add ( stamina_pict[stamina_stage] )
            else:
                add "dick5"

Alternatively, the screen can also be this one:
Python:
screen whatever:
    hbox:
        yalign 1.0
        xpos 750

        if ryan.lust == 100:
            $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
            if stamina_stage < 4:
                add ( "dick{}".format( stamina_stage + 1 ) )
            else:
                add "dick5"

Ultimately, because the Perl addict I am love this kind of dope, a the one liner version of both:
Python:
define stamina_effect = [ 25, 20, 10, 5 ]

label whatever
    $ stamina_stage = int(stamina / 20)
    $ lust += stamina_effect[stamina_stage] if stamina_stage < len( stamina_effect ) else 1

    if lust >= 100:
        $ lust = 0
        $ stamina += 20

screen whatever:
    hbox:
        yalign 1.0
        xpos 750

        if ryan.lust == 100:
            $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
            add ( "dick{}".format( stamina_stage + 1 ) if stamina_stage < 4 else "dick5" )


Python:
    if stamina >= 0 and stamina <= 20:
        $ lust += 25
[...]
It's a pure question of personal taste (I don't think it have a real impact regarding the performances, at least with Ren'Py), but I'll present an alternative:
Python:
if 0 <= stamina < 20:
    $ lust += 25
Depending on the person, some would read it more easily one way or the other.


And this conclude my purely useless contribution of the day.
 
  • Like
Reactions: rayminator

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,041
3,140
this shows what I really want to do

View attachment New Project.webm


















when you walk around to different locations the ryan's lust changes not the stamina
stamina will change while he works out at a gym or masturbates or sex

I have tried what 79flavors it didn't work all it did was show double or it didn't show anything
I haven't tried what anne O'nymous cause I don't understand it that well sorry

but that for the help
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,285
this shows what I really want to do
As I understand it, it's kind of the same concept than with the automatic masturbation in Super Powered, just with an opposite factor for the trigger.
When you character reach a certain level of lust, in can control itself and masturbate, or something similar. And the higher is his stamina, the more he's able to control itself.

The code gave by 79flavors should works fine for this.
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,041
3,140
As I understand it, it's kind of the same concept than with the automatic masturbation in Super Powered, just with an opposite factor for the trigger.
When you character reach a certain level of lust, in can control itself and masturbate, or something similar. And the higher is his stamina, the more he's able to control itself.

The code gave by 79flavors should works fine for this.
got it to work with some modifications


Python:
if orgasm_needed == True:
            if stamina >= 0 and stamina <= 20:
                $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
                add "dick1"
            elif stamina >= 21 and stamina <= 40:
                $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
                add "dick2"
            elif stamina >= 41 and stamina <= 60:
                $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
                add "dick3"
            elif stamina >= 61 and stamina <= 80:
                $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
                add "dick4"
            else:
                $ renpy.sound.play("/audio/maleorgasm.wav", loop=False,)
                add "dick5"
            #$ orgasm_needed = False

Python:
if clickType == "mapSelect":
            if stamina >= 0 and stamina <= 20:
                $ ryan.lust += 25
            elif stamina >= 21 and stamina <= 40:
                $ ryan.lust += 20
            elif stamina >= 41 and stamina <= 60:
                $ ryan.lust += 10
            elif stamina >= 61 and stamina <= 80:
                $ ryan.lust += 5
            else:
                $ ryan.lust += 1

        if ryan.lust >= 0:
            $orgasm_needed = False


        if ryan.lust >= 100:
            $ ryan.lust = 0
            $ orgasm_needed = True
            $ stamina += 20
            $ location = UIreturn
        $ location = UIreturn
 
  • Like
Reactions: anne O'nymous

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,041
3,140
I do have a slight problem with this code every time I click or click on a button or exit the sound play

never mind for some reason it fixed itself
 
Last edited: