Ren'Py $@#&!@!! Code Not Working

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,896
2,875
I have some code in my next release that I can't get to work the way I want it to. What I have are four animations, 2 doggy-style sex scenes at different speeds (slow and fast) and two side-sex scenes (also at slow and fast speeds). I have menus set up so that someone can click to (theoretically) speed things up or slow things down or switch between the two scenes. The problem is, whenever they speed it up, even when clicking on the slow down option, it stays the same speed. I'm posting the code here so y'all can look at it and maybe identify what I am getting wrong here.

Code:
label ep2_mc_shane_doggy:

window hide
show ep2_mc_shane_doggy

pause

menu:

     "Continue":                                   # <ep2_mc_shane_doggy>
        jump ep2_mc_shane_doggy

     "Go faster":
        jump ep2_mc_shane_doggy_faster

     "Cum":
        jump ep2_doggy_cumming

label ep2_mc_shane_doggy_faster:

window hide
show ep2_mc_shane_doggy_fast

pause

menu:

     "Continue":                                # <ep2_mc_shane_doggy_faster>
        jump ep2_mc_shane_doggy_faster

     "Go slower":
        jump ep2_mc_shane_doggy

     "Switch positions":
        jump ep2_mc_shane_side_sex

     "Cum":
        jump ep2_doggy_cumming

label ep2_mc_shane_side_sex:

window hide
show ep2_mc_shane_side_sex

pause

menu:

     "Continue":                                #  <ep2_mc_shane_side_sex>
        jump ep2_mc_shane_side_sex

     "Go faster":
        jump ep2_mc_shane_side_sex_faster

     "Switch positions":
        jump ep2_mc_shane_doggy

     "Cum":
        jump ep2_side_cumming


label ep2_mc_shane_side_sex_faster:

window hide
show ep2_mc_shane_side_sex_fast

pause

menu:

     "Continue":                                #  <ep2_mc_shane_side_sex_faster>
        jump ep2_mc_shane_side_sex_faster

     "Go slower":
        jump ep2_mc_shane_side_sex

     "Switch positions":
        jump ep2_mc_shane_doggy

     "Cum":
        jump ep2_side_cumming
Thanks to all for your help.
 
  • Like
Reactions: Vegeta

Jon_Sleeper

Member
Nov 14, 2018
284
364
try to use hide current image before jumping to a new label. I think this should work
Code:
show ep2_mc_shane_side_sex_fast

pause

menu:

     "Continue":                                #  <ep2_mc_shane_side_sex_faster>
        jump ep2_mc_shane_side_sex_faster

     "Go slower":
         hide ep2_mc_shane_side_sex_fast
        jump ep2_mc_shane_side_sex

     "Switch positions":
         hide ep2_mc_shane_side_sex_fast
        jump ep2_mc_shane_doggy

     "Cum":
         hide ep2_mc_shane_side_sex_fast
        jump ep2_side_cumming
 
  • Like
Reactions: seamanq

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,896
2,875
try to use hide current image before jumping to a new label. I think this should work
Code:
show ep2_mc_shane_side_sex_fast

pause

menu:

     "Continue":                                #  <ep2_mc_shane_side_sex_faster>
        jump ep2_mc_shane_side_sex_faster

     "Go slower":
         hide ep2_mc_shane_side_sex_fast
        jump ep2_mc_shane_side_sex

     "Switch positions":
         hide ep2_mc_shane_side_sex_fast
        jump ep2_mc_shane_doggy

     "Cum":
         hide ep2_mc_shane_side_sex_fast
        jump ep2_side_cumming
Worked like a charm. I thought I was accomplishing that with the window hide command before calling the image sequence, but apparently not. This has really been vexing me, so thank you for the assistance.
 

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,896
2,875
More code not working. This time, it's connected to a movie picker. Here is the code:

Code:
menu:

     "Romantic Comedy":
        jump ep2_romcom
        $ ep2movie = 1

     "Action movie":
        jump ep2_action_movie
        $ ep2movie = 2

     "Drama":
        jump ep2_drama
        $ ep2movie = 3

label ep2_action_movie:

scene bg tv action

label ep2_drama:

scene bg tv drama

label ep2_romcom:

scene bg tv romcom
Obviously, the code is supposed to select the movie then display the correct corresponding screen. No matter what I do, all it wants to do is show the first one (RomCom). Also, a numeric variable is supposed to be set to use later. Any idea what I am doing wrong here that it won't jump to the right screens? Thanks.
 

recreation

pure evil!
Respected User
Game Developer
Jun 10, 2018
6,327
22,776
The scene bg should be intendent inside the label. Maybe this will fix it already:
Code:
label ep2_action_movie:

    scene bg tv action

label ep2_drama:

    scene bg tv drama

label ep2_romcom:

    scene bg tv romcom
The numeric value isn't set because you jump to another label before it can be set. Move it above the jump and it will work.
 
  • Like
Reactions: seamanq

Epadder

Programmer
Game Developer
Oct 25, 2016
568
1,064
You need to set the variable before jumping :whistle:

Is that code exactly how it is in the game... or is there something in between the scene and label commands? ... If not Ren'py is just falling through the labels until it gets to a part of the code that makes it stop. If you put a pause or some sort of speech in-between the labels you should actually see the correct effect.

As a side note on indentation... please use it, it's good coding habit in general (I'm surprised Ren'py didn't shout at you for not using it) and when people want to help it increases the legibility of your code. :D
 

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,896
2,875
Ah yes I forgot about that.
As @Epadder said, use a pause after the scene bg.
Code:
label ep2_action_movie:
    scene bg tv action
    pause
label ...

Ok, let's try this again ...

Code:
menu:

     "Romantic Comedy":
        jump ep2_romcom
        $ ep2movie = 1

     "Action movie":
        jump ep2_action_movie
        $ ep2movie = 2

     "Drama":
        jump ep2_drama
        $ ep2movie = 3

label ep2_action_movie:

scene bg tv action
pause

label ep2_drama:

scene bg tv drama
pause

label ep2_romcom:

scene bg tv romcom
pause
I thought I had already included the menu where the variables were set. Now, with the pause in place, it goes to the right movie, but then when I click, it goes to the next movie type, and then the next movie type, before it gets to another script. It should be going only to the movie screen specified, then to the following script. Is there anything obvious here I am missing? The $ ep2movie is used for later logical questions in a script down the line:

Code:
if ep2movie == 1:
    scene bg tv romcom
elif ep2movie == 2:
    scene bg tv action
else:
    scene bg tv drama
Thanks for looking at it for me.
 

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,896
2,875
Ok, let's try this again ...

Code:
menu:

     "Romantic Comedy":
        jump ep2_romcom
        $ ep2movie = 1

     "Action movie":
        jump ep2_action_movie
        $ ep2movie = 2

     "Drama":
        jump ep2_drama
        $ ep2movie = 3

label ep2_action_movie:

scene bg tv action
pause

label ep2_drama:

scene bg tv drama
pause

label ep2_romcom:

scene bg tv romcom
pause
I thought I had already included the menu where the variables were set. Now, with the pause in place, it goes to the right movie, but then when I click, it goes to the next movie type, and then the next movie type, before it gets to another script. It should be going only to the movie screen specified, then to the following script. Is there anything obvious here I am missing? The $ ep2movie is used for later logical questions in a script down the line:

Code:
if ep2movie == 1:
    scene bg tv romcom
elif ep2movie == 2:
    scene bg tv action
else:
    scene bg tv drama
Thanks for looking at it for me.

Ok, looks like I got to the bottom of it. Here is the revised code:

Code:
label ep2_action_movie:

    scene bg tv action
    pause
    jump ep2movie_continue

label ep2_drama:

    scene bg tv drama
    pause
    jump ep2movie_continue

label ep2_romcom:

    scene bg tv romcom
    pause
    jump ep2movie_continue

label ep2movie_continue:

    menu:

        "Have another drink":
            $ ep2drink +1

        "Nah, better not.":
            $ ep2drink +0
After picking one of the three options, I had to tell it explicitly to jump to the next code sequence, otherwise it just went through each of the labels like there was no break. Now, when I pick a movie type, I get the right one displayed and it progresses further through the script. Thanks for your feedback everyone.
 

recreation

pure evil!
Respected User
Game Developer
Jun 10, 2018
6,327
22,776
Another possiblity without any jumps:
Code:
menu:

     "Romantic Comedy":
        $ ep2movie = 1 #romcom


     "Action movie":
        $ ep2movie = 2 #action movie


     "Drama":
        $ ep2movie = 3 # drama


label ep2_movie:
    if ep2movie == 2:
        scene bg tv action
    elif ep2movie == 3:
        scene bg tv drama
    else:
        scene bg tv romcom
    pause


label ep2movie_continue:
...
 
  • Like
Reactions: seamanq

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,971
16,228
For your initial problem, something like this should also do it :
[WARNING, I wrote it on the fly and I don't have animation right under the hand to validate it. I could have made an error or two, but the principle is here.]

Python:
label ep2_mc_shane_sex:

    window hide
    #  Default animation. The action start with doggy 
    # style.
    $ anim = "ep2_mc_shane_doggy"

    # This is an internal label. It can be reached only if you are
    # in the /ep2_mc_shane_sex/ label
    label .loop:

        #  Display the animation according to the value
        # of /anim/.
        show expression anim
        pause

        menu:
            "Continue":
                jump .loop

            #  Will be shown only if the animation name don't
            # end by "fast", so if it's actually the slow animation.
            "Go faster" if not anim.endswith( "fast" ):
                #  The substring "doggy" isn't part of the animation's
                # name, so the player expect fast side sex.
                if anim.find( "doggy" ) == -1:
                    $ anim = "ep2_mc_shane_side_sex_fast"
                # Have the substring "doggy", so the player expect
                # fast doggy style.
                else:
                    $ anim = "ep2_mc_shane_doggy_fast"
                jump .loop

            #  Will be shown only if the animation name end
            # by "fast", so if it's actually the fast animation.
            "Go slower" if anim.endswith( "fast" ):
                if anim.find( "doggy" ) == -1:
                    $ anim = "ep2_mc_shane_side_sex"
                else:
                    $ anim = "ep2_mc_shane_doggy"
                jump .loop

            "Switch positions":
                #  The substring "doggy" isn't part of the
                # animation name, so it's the side sex, 
                # switch to doggy style.
                if anim.find( "doggy" ) == -1:
                    $ anim = "ep2_mc_shane_doggy"
                else
                    $ anim = "ep2_mc_shane_side_sex"
                jump .loop

            "Cum":
                jump ep2_doggy_cumming
The principle is to take advantage of the capability of show to works with an expression instead of a literal displayable. This let you change the animation without having to change your code. It also let you take advantage of the conditional menu.
Then, all you need to do is to differentiate between the two animations, by searching if the name of the animation contain or not "doggy".
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,971
16,228
[WARNING, I wrote it on the fly and I don't have animation right under the hand to validate it.]
Well, now that I have enough to validate, I found an error... and also been able to validate a better approach. The principle stay the same than above, but this time it's a fully universal feature:

Python:
label start:
    # Parameters are : 
    #  - Base to build the animation name, where the "{}" mark 
    #  the place where text will be inserted. The first one is for
    #  the sexual position, the second one for speed.
    #  - List for the positions. You have two, so there's two 
    #  values, but you can have as many as you want.
    #  - List for the speeds. Here again there's the two 
    #  already defined in OP, but there can be more.
    #  To note, the first one is an empty string, since there's
    #  nothing to add to the name animation.
    # All this being called, so can be reused anywhere and anytime.
    # It just need a change in the parameters to have something
    # completely different.
    call sex_interface( "ep2_mc_shane_{}{}", [ "doggy", "side_sex" ], [ "", "_fast" ] )
    #  Here is the jump initially used in OP
    jump ep2_doggy_cumming
    "FINISHED"
    return


# Obviously, same meaning than above for the parameters
label sex_interface( base, style, speed ):

    window hide
    #  Position actually used. By default start with
    # the first one in the list. The list's indexes start
    # at 0, so use 0.
    $ styleID = 0
    #  Speed actually used. By default start with
    # the first one in the list, so the slowest.
    $ speedID = 0

    #  Here come an endless loop. It will repeat indefinitely
    # until the player choose the "cum" option.
    while True:

        # Force a clean up of the screen. Equivalent to a 
        # /hide something/.
        scene

        #  The magic happen here. Using the /base/ parameter,
        # the animation name is built according to the actual
        # configuration.
        #  Base being "ep2_mc_shane_{}{}", and default being
        # 0 for both /styleID/ and /speedID/, the result will be
        #  "ep2_mc_shane_" + the first entry in the /style/ list + the first entry in the /speed/ list
        # So : "ep2_mc_shane_" + "doggy" + "" = "ep2_mc_shane_doggy"
        show expression base.format( style[styleID], speed[speedID] )
        pause

        menu:
            #  Continue mean "no change", so just /pass/.
            "Continue":
                pass
                #  Ren'py will now continue with the first
                # statement after /menu/. There isn't here, so
                # it will loop the /while/ block which imply an
                # update of the animation to display.

            #  Will be shown only if the actual speed isn't the
            # last speed in the list.
            #  Reminder: List index start at 0. So the last index
            # is the /len/ of the list (number of entries) - 1.
            "Go faster" if speedID < len( speed ) - 1:
                #  If the player want to go faster, then increment
                # the speed. That's all what is needed.
                $ speedID += 1

            #  Will be shown only if the speed is higher than 0,
            # so if effectively the animation can be played slower.
            "Go slower" if speedID > 0:
                #  Less speed mean decreasing of the index.
                $ speedID -= 1

            "Switch positions":
                #  Switching mean playing the next animation
                # in the /style/ list. So, if it's not already the
                # last animation in the list ...
                if styleID < len( style ) - 1:
                    # ... increment the index ...
                    $ styleID += 1
                else:
                    # ... else loop back to the first index.
                    $ styleID = 0
                #  Optional, you can also choose to keep
                # the speed when switching position.
                $ speedID = 0

            "Cum":
                #  The player want to cum, it's time to hide
                # the animation.
                hide expression base.format( style[styleID], speed[speedID] )
                #  And just return to the place where the label was called.
                return
 
  • Like
Reactions: seamanq

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,896
2,875
Well, now that I have enough to validate, I found an error... and also been able to validate a better approach. The principle stay the same than above, but this time it's a fully universal feature:
Thanks @anne O'nymous very much for sharing this code with me. I did test it in my game, and it works flawlessly. The only thing that doesn't exactly work is that the cumshot at the end should end with whichever sex perspective is happening. i.e., there are two cumshots: ep2_doggy_cumming and ep2_side_cumming, and depending on which perspective the character is in, it should trigger the right one. I put this code in the spot where you had the single jump statement:

Code:
    if styleID == 1:

        jump ep2_doggy_cumming

    else:

        jump ep2_side_cumming

        label ep2_doggy_cumming:

        scene bg ep2 doggy cumming with hpunch

        $ renpy.pause (5.0) # will wait 5 sec or player's click to continue

        jump ep2_after_sex

        label ep2_side_cumming:

        scene bg ep2 side cumming with hpunch

        $ renpy.pause (5.0) # will wait 5 sec or player's click to continue

        jump ep2_after_sex
But it only shows the doggy cumming scene regardless of what animation is showing. Not sure what to do about it, but I am also not sure I want to hold up releasing the game at this point, as it's almost 2 months out, and I think my Patrons might be getting a bit itchy. If you have any ideas on how I could integrate it into your structure, I'm all ears.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,971
16,228
Code:
    if styleID == 1:

        jump ep2_doggy_cumming

    else:

        jump ep2_side_cumming

        label ep2_doggy_cumming:

        scene bg ep2 doggy cumming with hpunch
The idea is good, but there's few problems.

Firstly you forgot that list start at the index 0. So, for the doggy style, styleID value is 0.

Secondly (but perhaps it's because of your copy/paste), the label declaration is indented, and its content have the same indentation. It will greatly confuse Ren'py. For it, there will be an empty label named ep2_doggy_cumming, then a stand alone block of code (scene bg ep2 doggy cumming with hpunch and the following lines) [Note: I'm not sure if it will really be seen as stand alone and not directly ratached to the else block, see bellow].
Normally Ren'py is strong enough to works with this error, but here the stand alone block is indented as the same level than the content of the else block above. So there's risk that Ren'py have a really hard time here.

It's important to keep your labels at 0 level of indentation, unless it's a in which case it can be at an higher level of indentation. And to always indent the content of the label. It's the way it should be done (since labels are blocks), it make your code more readable and so, easier to maintain/debug, and it avoid that Ren'py lost its mind and don't really know what to do next.
Your code must look like this :
Python:
label myLabel:
    $ myVar = 1
    "Hi, welcome on board."

    label .localLabel:
        "It's not really new but so underused, a pitty / iteration number [myVar]."
        $ myVar += 1

    if myVar < 4:
        jump .localLabel
    else:
        "It was fun..."

    "but it's over now."
    "FINISHED"

If you have any ideas on how I could integrate it into your structure, I'm all ears.
Using directly styleID is possible since the variable wasn't , but I prefer to use the . It offer a better compatibility and a better readability/understanding of the code :

Python:
    [...]
            "Cum":
                hide expression base.format( style[styleID], speed[speedID] )
                #  Inform the calling code of what is the actual style by
                # returning it the actual /styleID/ value.
                return styleID

    [...]

label start:
    call sex_interface( "ep2_mc_shane_{}{}", [ "doggy", "side_sex" ], [ "", "_fast" ] )
    #  Called labels and screens store the value passed with /return/
    # (label) and /Return()/ (screen) inside the /_return/ variable. So
    # just test it and branch according to its value.
    #  As always, an array start at the index 0, so here you've only
    # two possiblities. And as reminder, the array is in the line above,
    # so few risk of inversion.
    if _return == 0:
        jump ep2_doggy_cumming
    elif _return == 1:
        jump ep2_side_cumming
 
  • Like
Reactions: seamanq

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,896
2,875
With that code in place and the jumps located elsewhere in the script, when viewing condition 1 (side sex), the game jumpes to a blank screen, says FINISHED, then goes back to the main screen.

The jumps were moved back to full flush left

Code:
label ep2_doggy_cumming:

scene bg ep2 doggy cumming with hpunch

$ renpy.pause (5.0) # will wait 5 sec or player's click to continue

jump ep2_after_sex

label ep2_side_cumming:

scene bg ep2 side cumming with hpunch

$ renpy.pause (5.0) # will wait 5 sec or player's click to continue
 

recreation

pure evil!
Respected User
Game Developer
Jun 10, 2018
6,327
22,776
With that code in place and the jumps located elsewhere in the script, when viewing condition 1 (side sex), the game jumpes to a blank screen, says FINISHED, then goes back to the main screen.

The jumps were moved back to full flush left

Code:
label ep2_doggy_cumming:

scene bg ep2 doggy cumming with hpunch

$ renpy.pause (5.0) # will wait 5 sec or player's click to continue

jump ep2_after_sex

label ep2_side_cumming:

scene bg ep2 side cumming with hpunch

$ renpy.pause (5.0) # will wait 5 sec or player's click to continue
again indented. Is this how your code looks in the script file or is it just unindented because of copy n paste?
Nothing in this part of the code should jump to the main screen so I guess it's another part of the code, or the intendation.
Watch the different style:

How it looks in your code:
Code:
label yourlabel:

somefancystuff
$ somevar = also_indented

label your_new_label:

somefancystuff
The same code how it should look:
Code:
label mylabel:

    somefancystuff
    $ somevar = also_indented

label my_new_label:

    somefancystuff
The content of a label must be indented.
Code:
label
    content
label
    content
The content of a query must be indented.
Code:
if
    do something
elif
    do something
else
    do something else
and so on.
 

polywog

Forum Fanatic
May 19, 2017
4,065
6,295
Some people prefer having full control of the sex scenes. For example, skip the handjob, and get right down to business.
And some people are annoyed having to wait 60 seconds for an animation to end with no way to bypass.
My suggestion to make the campers happy, is to put all the cards on the table.
Rather than going right into an animation, give them buttons to choose the sex position, and speed that they want, and or skip the scene. Some like to alternate between fast and slow a few times, "toggle on/off buttons" allow them to enable disable their favorites, from the playlist.