Ren'Py Unlocking an imagebutton after clicking three imagebuttons

shitcrap1

Member
Game Developer
Aug 15, 2023
171
773
So I don't know why I'm still strugglin with this... I've been trying to make three clickeable buttons unlock the last one to keep going in the story but I can't make it work.


Here is the code, the ones that are marked with the numers #1 #2 #3 are buttons that unlock the one that is marked as #unlockhere

I would appreciate any help.

Code:
init python:
    button_visible = True
    button_visible1 = True
    button_visible2 = True
    points = 0
    unlock_button2_points = 3

screen gasolinestation():
    add "Images/mapscreens/backround.png"

    imagebutton:
        focus_mask True
        xalign 0.560
        yalign 0.900
        auto "Images/Arrows/Arrowup_%s.png" action [ToggleScreen("gasolinestation"), Jump("gasoline_1")]

screen store():
    add "images/mapscreens/sto.png"
    #3
    if button_visible2 and points < unlock_button2_points:
        imagebutton:
            focus_mask True
            auto "images/Mapscreens/stot_%s.png" action [ToggleScreen("store"), Jump("cashier_1"), SetVariable("points", points + 1)]

    imagebutton:
        xalign 0.860
        yalign 0.550
        focus_mask True
        auto "images/arrows/arrowright_%s.png" action [ToggleScreen("store"), Jump("gasolinerestroom_1")]

    imagebutton:
        xalign 0.560
        yalign 0.900
        focus_mask True
        auto "images/arrows/arrowdown_%s.png" action [ToggleScreen("store"), Jump("gasoline_2")]

screen gasrestroom():
    add "sscene5"
    #Unlockhere
    if points >= unlock_button2_points:
        imagebutton:
            focus_mask True
            auto "images/mapscreens/Reestromin_%s.png" action [ToggleScreen("gasrestroom"), Jump("reestromin")]

    imagebutton:
        focus_mask True
        xalign 0.100
        yalign 0.900
        auto "images/arrows/arrowleft_%s.png" action [ToggleScreen("gasrestroom"), Jump("gasoline_1")]

    imagebutton:
        focus_mask True
        auto "images/mapscreens/backdoor_%s.png" action [ToggleScreen("gasrestroom"), Jump("gasbackdoor")]

    imagebutton:
        xalign 0.850
        yalign 0.900
        focus_mask True
        auto "images/arrows/arrowright_%s.png" action [ToggleScreen("gasrestroom"), Jump("momstore_1")]

screen backdoor1():
    add "worksh1"
    imagebutton:
        xalign 0.500
        yalign 0.900
        focus_mask True
        auto "images/arrows/arrowdown_%s.png" action [ToggleScreen("backdoor1"), Jump("gasolinerestroom_1")]

    imagebutton:
        focus_mask True
        auto "workshopdoor_%s.png" action [ToggleScreen("backdoor1"), Jump("workshop1")]

screen workshop_1():
    add "worksh2"
    #2
    if button_visible1 and points < unlock_button2_points:
        imagebutton:
            focus_mask True
            auto "scottbutton_%s.png" action [ToggleScreen("workshop_1"), Jump("workshop2"), SetVariable("points", points + 1)]

    imagebutton:
        focus_mask True
        xalign 0.500
        yalign 0.900
        auto "images/arrows/arrowdown_%s.png" action [ToggleScreen("workshop_1"), Jump("gasbackdoor")]

screen momstore1():
    add "mumstor1"
    #1
    if button_visible and points < unlock_button2_points:
        imagebutton:
            focus_mask True
            auto "mombutton1_%s.png" action [ToggleScreen("momstore1"), Jump("momstore_2"), SetVariable("points", points + 1)]

    imagebutton:
        focus_mask True
        xalign 0.100
        yalign 0.900
        auto "images/arrows/arrowleft_%s.png" action [ToggleScreen("momstore1"), Jump("gasolinerestroom_1")]
 
Last edited:

osanaiko

Engaged Member
Modder
Jul 4, 2017
2,553
4,639
Can you repost that inside a "code" block so the formatting is preserved? it would make it much easier to read.

1701921076370.png
 

shitcrap1

Member
Game Developer
Aug 15, 2023
171
773
Can you repost that inside a "code" block so the formatting is preserved? it would make it much easier to read.

View attachment 3149858
Code:
init python:
    button_visible = True
    button_visible1 = True
    button_visible2 = True
    points = 0
    unlock_button2_points = 3

screen gasolinestation():
    add "Images/mapscreens/backround.png"

    imagebutton:
        focus_mask True
        xalign 0.560
        yalign 0.900
        auto "Images/Arrows/Arrowup_%s.png" action [ToggleScreen("gasolinestation"), Jump("gasoline_1")]

screen store():
    add "images/mapscreens/sto.png"
    #3
    if button_visible2 and points < unlock_button2_points:
        imagebutton:
            focus_mask True
            auto "images/Mapscreens/stot_%s.png" action [ToggleScreen("store"), Jump("cashier_1"), SetVariable("points", points + 1)]

    imagebutton:
        xalign 0.860
        yalign 0.550
        focus_mask True
        auto "images/arrows/arrowright_%s.png" action [ToggleScreen("store"), Jump("gasolinerestroom_1")]

    imagebutton:
        xalign 0.560
        yalign 0.900
        focus_mask True
        auto "images/arrows/arrowdown_%s.png" action [ToggleScreen("store"), Jump("gasoline_2")]

screen gasrestroom():
    add "sscene5"
    #Unlockhere
    if points >= unlock_button2_points:
        imagebutton:
            focus_mask True
            auto "images/mapscreens/Reestromin_%s.png" action [ToggleScreen("gasrestroom"), Jump("reestromin")]

    imagebutton:
        focus_mask True
        xalign 0.100
        yalign 0.900
        auto "images/arrows/arrowleft_%s.png" action [ToggleScreen("gasrestroom"), Jump("gasoline_1")]

    imagebutton:
        focus_mask True
        auto "images/mapscreens/backdoor_%s.png" action [ToggleScreen("gasrestroom"), Jump("gasbackdoor")]

    imagebutton:
        xalign 0.850
        yalign 0.900
        focus_mask True
        auto "images/arrows/arrowright_%s.png" action [ToggleScreen("gasrestroom"), Jump("momstore_1")]

screen backdoor1():
    add "worksh1"
    imagebutton:
        xalign 0.500
        yalign 0.900
        focus_mask True
        auto "images/arrows/arrowdown_%s.png" action [ToggleScreen("backdoor1"), Jump("gasolinerestroom_1")]

    imagebutton:
        focus_mask True
        auto "workshopdoor_%s.png" action [ToggleScreen("backdoor1"), Jump("workshop1")]

screen workshop_1():
    add "worksh2"
    #2
    if button_visible1 and points < unlock_button2_points:
        imagebutton:
            focus_mask True
            auto "scottbutton_%s.png" action [ToggleScreen("workshop_1"), Jump("workshop2"), SetVariable("points", points + 1)]

    imagebutton:
        focus_mask True
        xalign 0.500
        yalign 0.900
        auto "images/arrows/arrowdown_%s.png" action [ToggleScreen("workshop_1"), Jump("gasbackdoor")]

screen momstore1():
    add "mumstor1"
    #1
    if button_visible and points < unlock_button2_points:
        imagebutton:
            focus_mask True
            auto "mombutton1_%s.png" action [ToggleScreen("momstore1"), Jump("momstore_2"), SetVariable("points", points + 1)]

    imagebutton:
        focus_mask True
        xalign 0.100
        yalign 0.900
        auto "images/arrows/arrowleft_%s.png" action [ToggleScreen("momstore1"), Jump("gasolinerestroom_1")]
 

osanaiko

Engaged Member
Modder
Jul 4, 2017
2,553
4,639
Hmm, I don't see a specific error but a few things that might help:
  1. Try putting the "SetVariable" action before the "Jump" - it's possible that the control flow is leaving the screen before that action is executed.
  2. The "button_visible", "button_visible2", "button_visible3" variables don't seem to do anything. If you want to disable the buttons after they are clicked the first time, you need to set them to false in the actions.
  3. "init python" blocks are quite old-school. it's better practice to use "define" for values that will not change during the game, such as "unlock_button2_points". and use "default" for creating and setting the initial value of variables that will change, like "points".
 
  • Heart
Reactions: shitcrap1

shitcrap1

Member
Game Developer
Aug 15, 2023
171
773
Hmm, I don't see a specific error but a few things that might help:
  1. Try putting the "SetVariable" action before the "Jump" - it's possible that the control flow is leaving the screen before that action is executed.
  2. The "button_visible", "button_visible2", "button_visible3" variables don't seem to do anything. If you want to disable the buttons after they are clicked the first time, you need to set them to false in the actions.
  3. "init python" blocks are quite old-school. it's better practice to use "define" for values that will not change during the game, such as "unlock_button2_points". and use "default" for creating and setting the initial value of variables that will change, like "points".
The problem was the order of the "Setvariable" code, thanks for the help and the advices, THANKS again!!
 
  • Heart
Reactions: osanaiko

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,978
16,236
Try putting the "SetVariable" action before the "Jump" - it's possible that the control flow is leaving the screen before that action is executed.
It's not possible, it's certain. Any screen action set after a screen action related to the control flow (Jump, Call and Return being the most used ones) will never be reached, and therefore never be processed.
 
  • Like
Reactions: osanaiko