[SOLVED] Problem with renpy.random.sample and imagebuttons

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: 40
Joined: Mon Jan 10, 2022 7:02 pm
Contact:

[SOLVED] Problem with renpy.random.sample and imagebuttons

#1 Post by Gigan »

Sorry everyone, was being dumb. One of the choices was badly coded, hence why it didn't appear.
Don't code at 1am folks.

Can't seem to find how to delete a topic so leavng it here so people can witness my dumbassery.


__________________________________________________________________________________

Hello everyone !

I have a little card game that triggers a renpy.random.sample variable. After that, I call a screen and the results of the variable appear as imagebuttons. Like this :

Image

Don't mind the grey-ish imagebutton, it's another thing.
My problem is, sometimes my imagebuttons appear and sometimes not :

Image

Here's my code :

Code: Select all

  default card_list = ["sandwitches_card", "lee_card", "typhon_card", "ruben_card"]

... 

    $ card_for_choices = renpy.random.choice(card_list)
    call screen choix_carte_x_1 with fastdissolve

...

screen choix_carte_x_1:
    if card_choices_1_pick == True or card_choices_2_picks == True: ### This one works fine.
        imagebutton:
            focus_mask True
            xpos 750
            ypos 50
            idle "cardgame/card_for_choice_2.png"
            action NullAction()
    if card_choices_1_pick == True: ### and this one too.
        imagebutton:
            focus_mask True
            xpos 475
            ypos 50
            idle "cardgame/card_for_choice.png"
            action [ SetVariable("picked_random", True), Jump("jeu")]

    if 'garland_card' in card_for_choices:
        imagebutton:
            focus_mask True
            if 'garland_card' in card_for_choices[0]:
                xpos 475
            else:
                xpos 200
            ypos 50
            idle "cardgame/ib_choice_garland.png"
            action Jump("carte_choix_garland")

    if 'ruben_card' in card_for_choices:
        imagebutton:
            focus_mask True
            if 'ruben_card' in card_for_choices[0]:
                xpos 475
            else:
                xpos 200
            ypos 50
            idle "cardgame/ib_choice_ruben.png"
            action Jump("carte_choix_ruben") 

    if 'lee_card' in card_for_choices:
        imagebutton:
            focus_mask True
            if 'lee_card' in card_for_choices[0]:
                xpos 475
            else:
                xpos 200
            ypos 50
            idle "cardgame/ib_choice_lee.png"
            action Jump("carte_choix_lee") 
...and so on.
From what I understand, the 2 picks of my renpy.random.sample are stored as card_for_choices[0] and card_for_choices[1], so I don't understand why sometimes one appear and the other not. And it's completely random. Sometimes it's the left one, sometimes it's the right one.

Begging for your help. Brain is a mess.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], RVNSN