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

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,888
2,857
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.

Here is the content that is getting borked:

Code:
label ep2_sexanimation:
    # 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
    if _return == 0:
        jump ep2_doggy_cumming
    elif _return == 1:
        jump ep2_side_cumming
    "FINISHED"
    return
And here is the code for the jumps:

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

    jump ep2_after_sex

label ep2_after_sex:

    scene bg ep2 shane sleep wake

    $ renpy.pause (5.0) # will wait 5 sec or player's click to continue
When the button "Cum" is clicked, it jumps straight to a blank screen that says FINISHED, then bounces out to the game main menu. I am not sure why this is happening.
 

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,888
2,857
This code problem is literally the last thing that is holding me up from releasing the next Episode.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
9,949
14,548
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.
Ren'py is just a "stupid machine". As long as you don't tell him to change its direction (jump, call, etc) it go straight ahead. You've a jump ep2_after_sex at the end of your ep2_doggy_cumming label, but there's nothing at the end of the ep2_side_cumming one. Perhaps that it's just you who forgot to copy/paste it, but like the code is in your comment, once he passed the line scene bg ep2 side cumming with hpunch, Ren'py will continue with whatever code is following. This even if there's tons of blank lines or comment, init blocks, screen blocks, or any kind of statements working at init level (like default by example), before the next effective code line, and even if this effective code line is inside a label.

Python:
label start:
    "It start here"

define blabla = "blibli"



# some comment
# just for fun


default universalAnswer = 42

screen myScreen:
    modal True

    text "just to give it some content"

init -100 python:

    def myFnct():
        pass

label continue:
    "then continue here"
So, I assume that in this particular case, after the ep2_side_cumming label, there's something displaying a blank screen, then "FINISHED", followed by a return statement.

Also, like @recreation reminded, be careful with the indentation, it can really change the whole behavior of the code you write. As human, there's times when we can't understand what the not indented code mean, so imagine for a machine. It can't make guess, just assume that things are like they are supposed to be.

Finally, you don't need to write things like $ renpy.pause( 5.0 ). There's a pause Ren'py statement (apparently still undocumented :/). So pause 5.0 will do exactly the same thing. You need the Python equivalent only when you want the pause to hard (none skippable).
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
9,949
14,548
[oops, you added something while I was busy writing my answer and doing too many others things]

And here is the code for the jumps:
They aren't in fault here. Apparently there's something wrong with the returned value, that apparently is neither 0 nor 1.
The best way to find what's the problem is to change a little the code :
Python:
    if _return == 0:
        jump ep2_doggy_cumming
    elif _return == 1:
        jump ep2_side_cumming
    else:
        "The returned value is [_return]"
    "FINISHED"
Perhaps it's my fault, I'm a little ill actually, I can have missed something or messed up with something in my own code.
 
  • Like
Reactions: seamanq

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,888
2,857
Here is the whole code segment so you can see it all in context:

Code:
label ep2_sexanimation:
    # 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

    if _return == 0:
        jump ep2_doggy_cumming
    elif _return == 1:
        jump ep2_side_cumming
    else:
        "The returned value is [_return]"
    "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

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

label ep2_after_sex:

    scene bg ep2 shane sleep wake

    $ renpy.pause (5.0) # will wait 5 sec or player's click to continue
I am getting a response that The returned value is None, then it returns to the main screen. I am suspecting I just have something in the wrong place.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
9,949
14,548
Here is the whole code segment so you can see it all in context:

Code:
[...]
            "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

label ep2_doggy_cumming:
[...]
Found the error.

Actually if you play this code, it should end with :
"The returned value is None"
"FINISHED"
Then return to the main screen

You kept return as it. You probably where thinking something else and made one change, and thought that you already made the other one ; which ended never be made.
It should be :
Code:
                #  And just return to the place where the label was called.
                return styleID
And now it should works fine.
 
  • Like
Reactions: seamanq

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,888
2,857
Found the error.

Actually if you play this code, it should end with :
"The returned value is None"
"FINISHED"
Then return to the main screen

You kept return as it. You probably where thinking something else and made one change, and thought that you already made the other one ; which ended never be made.
It should be :
Code:
                #  And just return to the place where the label was called.
                return styleID
And now it should works fine.
Bingo!!! It works perfectly now. I am going to have to dissect the code that you wrote so I can understand what is going on there. This is quite beyond my current level of Python knowledge. Thank you again for your help.
 
  • Like
Reactions: anne O'nymous

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
9,949
14,548
I am going to have to dissect the code that you wrote so I can understand what is going on there.
That's why I put a lot of comments. It probably don't explain everything (it's obvious code for my (more or less) 30 years of experience, so I can have missed few things) but I tried to make it so you can fill the blank


Thank you again for your help.
You're welcome.
 

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,888
2,857
That's why I put a lot of comments. It probably don't explain everything (it's obvious code for my (more or less) 30 years of experience, so I can have missed few things) but I tried to make it so you can fill the blank




You're welcome.
People like you are part of the reason this is such an amazing place. Thank you so much for your kind contribution to my learning process and to my game. I'll shoot you a link once it's built so you can see the results of your work in context.
 

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,888
2,857
That's why I put a lot of comments. It probably don't explain everything (it's obvious code for my (more or less) 30 years of experience, so I can have missed few things) but I tried to make it so you can fill the blank




You're welcome.
@anne O'nymous

Well, I released the game into the wild, and now it's throwing off errors. When the game is saved during the sex animation or after the sex animation, it gives a traceback error.

Here's the error:

I'm sorry, but an uncaught exception occurred.

While running game code:
File "renpy/common/00action_file.rpy", line 452, in __call__
renpy.load(fn)
Exception: Style '__setstate__' does not exist.

Any idea what might be causing this? It seems to be specific to the code calling the animation sequence.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
9,949
14,548
Exception: Style '__setstate__' does not exist.
Er... I'll look at the game, but it's really strange. The error say that Ren'py tried to save a style... but why would he want to do that ??? :/
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
9,949
14,548
Any idea what might be causing this? It seems to be specific to the code calling the animation sequence.
Alright, my bad. I thought about the code and forgot to thought about Ren'py behavior.
Rename the style list into sexStyle and it will works :
episode_2.rpy:1031
label sex_interface( base, sexStyle, speed ):
episode_2.rpy:1057
show expression base.format( sexStyle[styleID], speed[speedID] )
episode_2.rpy:1088
if styleID < len( sexStyle ) - 1:
episode_2.rpy:1101
hide expression base.format( sexStyle[styleID], speed[speedID] )
 

seamanq

Well-Known Member
Game Developer
Aug 28, 2018
1,888
2,857
Thank you. It appears to be working in my revised version. I have sent it to the reader who expressed concerns about the bug to see if s/he can replicate it.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
9,949
14,548
I have sent it to the reader who expressed concerns about the bug to see if s/he can replicate it.
It will not, it was 100% my fault. Like I said, I was too focused on the code and forgot that style is also the place where Ren'py store the different styles used by the screens.
The way Ren'py works make it that the error don't appear immediately (the screen don't directly address style but a reference of it). But once Ren'py need to load, boom. It try to load the complex tree structure that are the styles, inside what have became a integer... and, well, as you've seen, it don't works.
So, just changing the name of the list, to not override style anymore was really enough to solve the problem.

If someone still was in doubt, it's the undeniable proof that you must always be careful when you code. Everyone can make an error, even people who have a lot of knowledge and experience.