Problem: Random buttons or image buttons.

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
LongHairRkr
Newbie
Posts: 9
Joined: Fri Aug 02, 2019 1:53 am
Projects: the Neighborhood
Contact:

Problem: Random buttons or image buttons.

#1 Post by LongHairRkr »

Help gang!

I know there has to be a way to do this but I'm too smart to figure this out. :D

What I'd like to do is have two image buttons from a list of characters so that you can click each one to jump to an event. I want to make these characters randomly picked when you come into the "room" and not pick the same character in both slots ever.

Example:
List one: Jessica, James, John, Mike, Robert, and Michelle
List two: Jessica, James, John, Mike, Robert, and Michelle

I want it to pick one from list one, and then one from list two, but never have Mike (or whoever) picked in BOTH lists, only one. These would appear as imagebuttons for each character as in:

imagebutton auto "maps/peaseyhouse/buttons/mike_%s.webp" action Jump ("mdiningroom") xalign 0.5 yalign 0.97
imagebutton auto "maps/peaseyhouse/buttons/jessica_%s.webp" action Jump ("jdiningroom") xalign 0.5 yalign 0.97

I'm certain there must be a way. Hope you can help!

Thanks in advance!

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Problem: Random buttons or image buttons.

#2 Post by Per K Grok »

LongHairRkr wrote: Thu Apr 16, 2020 7:51 pm Help gang!

I know there has to be a way to do this but I'm too smart to figure this out. :D

What I'd like to do is have two image buttons from a list of characters so that you can click each one to jump to an event. I want to make these characters randomly picked when you come into the "room" and not pick the same character in both slots ever.

Example:
List one: Jessica, James, John, Mike, Robert, and Michelle
List two: Jessica, James, John, Mike, Robert, and Michelle

I want it to pick one from list one, and then one from list two, but never have Mike (or whoever) picked in BOTH lists, only one. These would appear as imagebuttons for each character as in:

imagebutton auto "maps/peaseyhouse/buttons/mike_%s.webp" action Jump ("mdiningroom") xalign 0.5 yalign 0.97
imagebutton auto "maps/peaseyhouse/buttons/jessica_%s.webp" action Jump ("jdiningroom") xalign 0.5 yalign 0.97

I'm certain there must be a way. Hope you can help!

Thanks in advance!
You can use this to pick random names where nameA and nameB will never be the same.

Code: Select all


default listA=["Jessica", "James", "John", "Mike", "Robert", "Michelle"]
default listB=[0,1,2,3,4,5]
default pickA=0
default pickB=0
default nameA=0
default nameB=0

label start:

    $ listB=[0,1,2,3,4,5]                                             ### reset listB
    $ pickA=listB.pop(renpy.random.randint(0,5))    ### pick random from full list and remove chosen
    $ pickB=listB.pop(renpy.random.randint(0,4))    ### pick random from decimated list

    $ nameA=listA[pickA]
    $ nameB=listA[pickB]

    "[nameA]:[nameB]"     ### show result

    jump start

To show a button with the right image you can use if/elif

Code: Select all


if pickA==0:
        imagebutton auto "maps/peaseyhouse/buttons/jessica_%s.webp" action Jump ("mdiningroom") xalign 0.5 yalign 0.97    
elif pickA==1:
        imagebutton auto "maps/peaseyhouse/buttons/james_%s.webp" action Jump ("mdiningroom") xalign 0.5 yalign 0.97    

-----


LongHairRkr
Newbie
Posts: 9
Joined: Fri Aug 02, 2019 1:53 am
Projects: the Neighborhood
Contact:

Re: Problem: Random buttons or image buttons.

#3 Post by LongHairRkr »

That worked beautifully! Thank you SO much!!

Post Reply

Who is online

Users browsing this forum: Google [Bot]