Ren'Py Way to have an imagebutton change animation loops (ie: change camera angle) [SOLVED]

moose_puck

Active Member
Sep 6, 2021
741
1,664
I'm wearing out my keyboard looking for an answer here, but what i need is a way to change an imagebutton call, so that I can cycle through 2 or 3 animation loops.

So far, I've managed to create some simple 3 or 4 render animation loops and I've also created a camera angle imagebutton that works, so when you click it, it jumps to the second image loop. Where I am hitting a wall is trying to figure out how to make the imagebutton toggle so that i can click it to cycle through each loop. IE: Watching loop 1, button takes you to loop 2, click it again and it takes you to loop 3, then the next click cycles back to loop 1. That sort of thing.

Is there a way to use a function in the screen action part of the imagebutton, using a variable (say "cam_switch") so that when you are in Loop 1, "cam_switch" is set to 2, and when you jump to Loop 2, the variable "cam_switch" is changed to 3? Then be able to use that variable in the Action Jump part of the image button?

Here's how the loops look...


Python:
label sex_2_cam_1:

    $ cam_switch = 2

    show loop:
        alpha 0.
        "a0_s02_r075"
        linear 1. alpha 1.
        block:
            "a0_s02_r075"
            .5
            "a0_s02_r076"
            .5
            "a0_s02_r077"
            .5
            "a0_s02_r078"
            .5
            "a0_s02_r077"
            .5
            "a0_s02_r076"
            repeat

    call screen cam_angle

And here's the cam_angle screen

Python:
screen cam_angle():

    imagebutton:
        yalign 0.05
        xalign 0.95
        auto ("gui/camera_%s.png")
        action Jump("sex_2_cam_2")
The above works fine for just jumping from loop one to loop two but when I I've tried imputing the variable directly into the Jump statement, it doesn't want to work. Says it can't find the label action Jump("sex_2_cam_[cam_switch]")

I suspect I that (1) I don't know the proper syntax for using functions this way or (2) Renpy doesn't allow it used for Screen Actions. I've seen this type of image button used in other games, but I don't have any examples, atm.

Any suggestions?
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,285
Any suggestions?
Well, I have three.


Suggestion number one:
Python:
screen cam_angle():

    # Current angle shown
    default angle = 1

    imagebutton:
        yalign 0.05
        xalign 0.95
        auto ("gui/camera_%s.png")
        # Assuming that there's 5 angles.
        # /!\ Normally /angle/ value should be updated when you reach the /Jump/. But if it's not
        # the case, just use "angle + 1".
        action [ If( angle < 5, SetScreenVariable( "angle", angle + 1 ), SetScreenVariable( "angle", 1 ) ), Jump("sex_2_cam_{}".format( angle ) ) ]

Suggestion two:
Python:
image sex_2_cam_1:
        alpha 0.
        "a0_s02_r075"
        linear 1. alpha 1.
        block:
            "a0_s02_r075"
            .5
            "a0_s02_r076"
            .5
            "a0_s02_r077"
            .5
            "a0_s02_r078"
            .5
            "a0_s02_r077"
            .5
            "a0_s02_r076"
            repeat

image sex_2_cam_2:
     ...

screen sex_2():

    # Current animation shown
    default animation = 1

    add "sex_2_cam_{}".format( animation )

    imagebutton:
        yalign 0.05
        xalign 0.95
        auto ("gui/camera_%s.png")
        # Assuming that there's 5 animation.
        action If( animation < 5, SetScreenVariable( "animation", animation + 1 ), SetScreenVariable( "animation", 1 ) )

    textbutton "close":
        xalign 0.5 yalign 0.9
        action Return()
Suggestion three:
Python:
image sex_2_cam_1:
     ...

image sex_2_cam_2:
     ...

screen sex( base, frames ):

    # Current animation shown
    default animation = 1

    add "{}{}".format( base,animation )

    imagebutton:
        yalign 0.05
        xalign 0.95
        auto ("gui/camera_%s.png")
        action If( animation < frames, SetScreenVariable( "animation", animation + 1 ), SetScreenVariable( "animation", 1 ) )

    textbutton "close":
        xalign 0.5 yalign 0.9
        action Return()

label whatever:
    # Assuming that there's 5 animations
    call screen sex( "sex_2_cam_", 5 )
The last one is the most complete since it don't need external labels, and a single screen is all you need to have a multi angle for all your animations.


Edit: Fixed a typo in the code.
 
Last edited:
  • Like
Reactions: moose_puck

moose_puck

Active Member
Sep 6, 2021
741
1,664
The last one is the most complete since it don't need external labels, and a single screen is all you need to have a multi angle for all your animations.
Thank you for the quick response.

I tried the third option and didn't get any errors, but clicking the imagebutton doesn't seem to advance it to image sex_2_cam_2. It just keeps looping sex_2_cam_1. The "close" textbutton exits properly.

Does it matter if the image frames are full screen renders? Like, do I need to use scene or something to clear the screen when switching?
 

mickydoo

Fudged it again.
Game Developer
Jan 5, 2018
2,446
3,548
I use kindergarten code

default camera_1 = False
default camera_2 = False
default camera_3 = False
default camera_4 = False



Then when I play say fuck_1 I make camera_1 True

When I play fuck_2 I make camera_1 False and camera 2 True

etc etc

Then just use if statements in the icon screen
Python:
screen sex_buttons:
    imagebutton:
        if camera_1:
            idle "icons/camera1.png"
            hover "icons/camera.png"
            xalign 0.98
            yalign 0.03
            action Jump("fuck_2")
            
          if camera_2:
            idle "icons/camera1.png"
            hover "icons/camera.png"
            xalign 0.98
            yalign 0.03
            action Jump("fuck_1")   
            
        if camera_3:
            idle "icons/camera1.png"
            hover "icons/camera.png"
            xalign 0.98
            yalign 0.03
            action Jump("fuck_4")
 
  • Like
Reactions: moose_puck

moose_puck

Active Member
Sep 6, 2021
741
1,664
Python:
action If( animation >= frames, SetScreenVariable( "animation", animation + 1 ), SetScreenVariable( "animation", 1 ) )
Figured it out!

You have a Greater Than sign in the code I quoted above. It needs to be a Less Than.

So that fixed it switching animations. But then I had a hitch where when you cycled through the last animation, the loop would pause until you hit the imagebutton again. I 'guessed' that the series included a "0", so it was looking for one extra animation that I didn't have. So i reduced the limiting number by 1 (so the 5 became a 4 in your example).

That fixed it. Seems to work great now, and i can apply this to the zillion other animations I'll be making.

My brain hurts. I've been coding this scene all day, lol.

Thanks for the help again anne O'nymous!
 

moose_puck

Active Member
Sep 6, 2021
741
1,664
I use kindergarten code

.. snip
Thanks! This is another way I didn't think of. But it is closer to the way I was kinda going earlier today, with all the variables. I realized though, that I would soon get variable bloat. And then I found out that you can't exit these pseudo-animation loops with the normal key/mouse inputs.

anne O'nymous's solution eliminates the need for all those variables. Plus, it will be easy to cut and paste this code for any scene. The only thing I will probably change is that, instead of using a "close" textbutton to exit the loops, I will put another imagebutton up. Like an arrow or something. So one button changes the camera angle and the other button exits the loop.

Easier to navigate when you are down a hand *grin*.

A productive day today!

Thanks both of you.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,285
Figured it out!

You have a Greater Than sign in the code I quoted above. It needs to be a Less Than.

So that fixed it switching animations. But then I had a hitch where when you cycled through the last animation, the loop would pause until you hit the imagebutton again. I 'guessed' that the series included a "0", so it was looking for one extra animation that I didn't have. So i reduced the limiting number by 1 (so the 5 became a 4 in your example).

That fixed it. Seems to work great now, and i can apply this to the zillion other animations I'll be making.
Sorry about this. It happen sometimes when I wrote on the fly, my fingers type faster than my brain works.
 

moose_puck

Active Member
Sep 6, 2021
741
1,664
Sorry about this. It happen sometimes when I wrote on the fly, my fingers type faster than my brain works.
I know the feeling. Right now my brain is numb. I probably would have noticed it earlier, but instead I spent an hour trying other things. The only coding I ever really did before was HTML 4 and some php scripts 20+ years ago - when I had some websites.

Unless you want to count Atari BASIC from 1985, haha.

But then my brain woke up and I said "How is that going to increment up with a > sign?"

I'm happy though. I'll jump on this tomorrow and clean the mess up that I made with this scene file, troubleshooting all this.