Ren'py Python code interaction question

L33ch

Newbie
Jun 11, 2017
93
175
So, I'm making a simple game to try and nail down the basics of coding for myself and I've run across a weird question that is beyond my current knowledge.

I've got a whole bunch of screens set up that let me jump from one to the next in ren'py via image buttons. All the images are codified for easy processing/linking, and it works without issue so far. (For reference, the code I'm using is (for example because you don't need the filenames -)

screen ImageAAA1AA:

imagebutton auto "images/Image/ButtonImage/Image_Image_%s.png" xpos 810 ypos 425 action [Show("ImageAAA1AB"), ToggleScreen("ImageAAA1AA")]


It's working great. What I'm wondering though, is, as you might have noticed - the 4th digit in the file names is indeed a number.

I'm wondering if it's possible to create an imagebutton that can stay on screen, and will just change that 1 to a 2, regardless of which screen is currently called, so that it will change the destination of the image button you currently see.

For example, I'm hoping it would be:

"Press this imagebutton"

action[Show("imageAAA1AA")} - becomes action[(show("imageAAA2AA")]

And then with the same unaltered "Press this imagebutton" hypothetical code, it could also cause:

action {Show("ABC1AA")] to become action[Show("ABC2AA")]

without having to program individual buttons for every screen. (Which is fine, just time consuming so I'm hoping for this kind of a shortcut.)

I haven't tried it yet, but I'm assuming I might be able to define 1 = 1 and then have the "Press this imagebutton" be $ 1 = 2 ?

Any help or insight would be great, I'm still hella new to coding.
 

KiaAzad

Member
Feb 27, 2019
291
214
you can store your button in a variable and change that variable when jumping around.
Python:
default test_button = [

    "image_name",

    Jump("Image_name"),

]


screen test_screen:

    button:

        add test_button[0]

        action test_button[1]
it's untested code but should work because, I've done something similar in my old 0GUI code for the main and navigation menus, you can find it on guithub and peek into it if you want.
 
  • Like
Reactions: L33ch

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,971
16,225
It's working great. What I'm wondering though, is, as you might have noticed - the 4th digit in the file names is indeed a number.

I'm wondering if it's possible to create an imagebutton that can stay on screen, and will just change that 1 to a 2, regardless of which screen is currently called, so that it will change the destination of the image button you currently see.
Yes it is:

Python:
screen whatever():

   default digit = "1"

   add "whateverimage_{}".format( digit )

  if digit <= 5:
      imagebutton:
          auto "images/Image/ButtonImage/Image_Image_%s.png"
          xpos 810 ypos 425 
          action [ SetScreenVariable( "digit", digit + 1) ]
 
  • Like
Reactions: L33ch

L33ch

Newbie
Jun 11, 2017
93
175
Yes it is:

Python:
screen whatever():

   default digit = "1"

   add "whateverimage_{}".format( digit )

  if digit <= 5:
      imagebutton:
          auto "images/Image/ButtonImage/Image_Image_%s.png"
          xpos 810 ypos 425
          action [ SetScreenVariable( "digit", digit + 1) ]
Awesome, thanks.
 

L33ch

Newbie
Jun 11, 2017
93
175
you can store your button in a variable and change that variable when jumping around.
Python:
default test_button = [

    "image_name",

    Jump("Image_name"),

]


screen test_screen:

    button:

        add test_button[0]

        action test_button[1]
it's untested code but should work because, I've done something similar in my old 0GUI code for the main and navigation menus, you can find it on guithub and peek into it if you want.
Thanks, I'll give it a shot.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,971
16,225
Awesome, thanks.
Side note: It's too hot today and I was at works when I wrote this. There's perhaps a typo in the way I presented add. So, you'll perhaps have to workaround this part. But the logic stay the same.
 
  • Like
Reactions: L33ch