[SOLVED] Making the player click on multiple imagebuttons before closing the screen

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Gigan
Regular
Posts: 29
Joined: Mon Jan 10, 2022 7:02 pm
Contact:

[SOLVED] Making the player click on multiple imagebuttons before closing the screen

#1 Post by Gigan »

Hello everybody !
I'm making a cardgame and I'm stuck at something that seemed easy in my head (and is probably, for most of you).

Basically, I want 6 cards to be aligned so the player can choose 3 so reveal their values. Once he chose those, the other 3 become unclickable and he must pick one of the 3 cards he revealed.

Here, an example with 3 cards.
Image

I have several problems :
- 1 - I want those imagebuttons to appear one after the other. The only solution I found is to put them in different screens, which I know is not ideal. I then "show" the screens one after the other with "pause" in between.

Code: Select all

label start:

    e "start"
    show screen card_malus with dissolve
    pause 0.5
    show screen card_malus_2 with dissolve
    pause 0.5
    show screen card_malus_3 with dissolve
    pause
    e "end"
    return
...to anyone who can code, I apologize for this monstruosity.

- 2 - Using several screens, I can't use the "call" command, as only the 1st screen would appear before I click on it. So using "show", the buttons appear and are useable, except the game doesnt care if the player use the buttons or not and jump to the next line of dialogue if they click somewhere else.

I suppose the solution would be to call a screen with all the buttons but
==> I have no idea how to make them appear one after the other and
==> I tried it first and the screen obviously disappeared after clicking on 1 single button.

Last thing, is it possible to explain how I can make the buttons unclickable once the player clicked on 3 of them ?

Sorry to bother. I don't think my code will be useable at all, as it's very barebone and I'm myself ashamed of it, but here's the full thing :

Code: Select all

default card_malus_1 = False
default card_malus_2 = False
default card_malus_3 = False
default card_malus_count = 0

label start:

    e "start"
    show screen card_malus with dissolve
    pause 0.5
    show screen card_malus_2 with dissolve
    pause 0.5
    show screen card_malus_3 with dissolve
    pause
    e "end"
    return

screen card_malus:
    if not card_malus_1:
        imagebutton:
            focus_mask True
            xpos 200
            ypos 100
            idle "cardgame/card_poison_recto.png"
            action [SetVariable("card_malus_1", True), SetVariable("card_malus_count", card_malus_count + 1)]
    else:
        imagebutton:
            focus_mask True
            xpos 200
            ypos 100
            idle "cardgame/card_poison_verso_1.png"

screen card_malus_2:
    if not card_malus_2:
        imagebutton:
            focus_mask True
            xpos 400
            ypos 100
            idle "cardgame/card_poison_recto.png"
            action [SetVariable("card_malus_2", True), SetVariable("card_malus_count", card_malus_count + 1)]
    else:
        imagebutton:
            focus_mask True
            xpos 400
            ypos 100
            idle "cardgame/card_poison_verso_2.png"

screen card_malus_3:
    if not card_malus_3:
        imagebutton:
            focus_mask True
            xpos 600
            ypos 100
            idle "cardgame/card_poison_recto.png"
            action [SetVariable("card_malus_3", True), SetVariable("card_malus_count", card_malus_count + 1)]
    else:
        imagebutton:
            focus_mask True
            xpos 600
            ypos 100
            idle "cardgame/card_poison_verso_3.png"
Last edited by Gigan on Sat Feb 17, 2024 9:20 am, edited 1 time in total.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2438
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Making the player click on multiple imagebuttons before closing the screen

#2 Post by Ocelot »

1) You can use ATL transformations with arguments to make button appear after some time.

Code: Select all

transform delay_appear(delay=0.0):
    alpha 0.0
    pause delay
    linear 0.5 alpha 1.0

screen cards():
    imagebutton:
        at delay_appear(0.0)
        # . . .
    imagebutton:
        at delay_appear(0.5)
        # . . .
    imagebutton:
        at delay_appear(1.0)
        # . . .
2) As you now have a single screen, you can either call screen, or use modal True to force player to interact with this screen.
Last) Use more conditions. Specifically I would suggest using If Action ( https://www.renpy.org/doc/html/screen_actions.html#If ) to return NullAction() when you have already selected 3 cards. Likewise you can make selected cards not active, until you selected all of them.
< < insert Rick Cook quote here > >

Gigan
Regular
Posts: 29
Joined: Mon Jan 10, 2022 7:02 pm
Contact:

Re: Making the player click on multiple imagebuttons before closing the screen

#3 Post by Gigan »

Works like a charm (also learned a bunch of stuff) ! Thank you king o/ !

Post Reply

Who is online

Users browsing this forum: Amazon [Bot]