I was thinking about creating a mini game about pulling out random items from a container. Let's say I have a list:
default container = [*stuff possible to pick up*]
What is the easiest way to write a code randomizing and then picking out single items from that list?
[Solved] Taking out random items from list?
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.
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.
[Solved] Taking out random items from list?
Last edited by Doeny on Thu Oct 06, 2022 6:37 pm, edited 2 times in total.
- Ocelot
- Eileen-Class Veteran
- Posts: 1882
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: Taking out random items from list?
Code: Select all
# Do you want to pick up a random item and leave it in container?
$ item = renpy.random.choice(container)
# Do you want to pick random item and remove it?
$ renpy.random.shuffle(container) # Once at the beginning
# . . .
$ item = container.pop()
< < insert Rick Cook quote here > >
Re: Taking out random items from list?
It works perfectly, thank you very much, Ocelot!Ocelot wrote: ↑Thu Oct 06, 2022 5:57 amCode: Select all
# Do you want to pick up a random item and leave it in container? $ item = renpy.random.choice(container) # Do you want to pick random item and remove it? $ renpy.random.shuffle(container) # Once at the beginning # . . . $ item = container.pop()
Who is online
Users browsing this forum: Google [Bot], Majestic-12 [Bot]