Shuffle choice order
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.
Shuffle choice order
Hello! I hope someone can help me.
Is it possible to make the choices appear in a random order?
So that the choices ABC get either ABC, ACB, BCA, BAC, CAB or CBA, everytime you come to this choice.
I would like to write the choices in the right order, so it's easyer to manage for me as a gamemaker, but the choices shouldn't be obvious for the player.
Is it possible to make the choices appear in a random order?
So that the choices ABC get either ABC, ACB, BCA, BAC, CAB or CBA, everytime you come to this choice.
I would like to write the choices in the right order, so it's easyer to manage for me as a gamemaker, but the choices shouldn't be obvious for the player.
- SleepKirby
- Veteran
- Posts: 255
- Joined: Mon Aug 09, 2010 10:02 pm
- Projects: Eastern Starlight Romance, Touhou Mecha
- Organization: Dai-Sukima Dan
- Location: California, USA
- Contact:
Re: Shuffle choice order
Alex is right, but you can also randomize all of your choice menus automatically, by modifying your choice screen. That way you don't have to remember to randomize the choices every time you write a menu.
Another idea I'd like to mention is to order the choices alphabetically. That way, the choices are scrambled from their original order, but they'll also be presented in the same order every time. This is what I do in my game. To do this, you could change the above function to the following:
Code: Select all
screen choice:
# Add this line.
$ shuffle_items(items)
window:
style "menu_window"
vbox:
style "menu"
for caption, action, chosen in items:
...
Code: Select all
init python:
def shuffle_items(items):
renpy.random.shuffle(items)
Code: Select all
init python:
import operator
def shuffle_items(items):
# Each choice item is a tuple of three elements: caption, action, and chosen.
# We want to alphabetize by the text display for the choice. This is the
# caption, the first element. To sort by the first element, use
# itemgetter(0) as the sorting key.
# More info on sorting: http://wiki.python.org/moin/HowTo/Sorting/
items.sort(key=operator.itemgetter(0))
Re: Shuffle choice order
Ah, yes it worked!
I'm glad that there is a simple way of solution, SleepKirby. Thank you, thank you!
And thank you both for answering my question.
I'm glad that there is a simple way of solution, SleepKirby. Thank you, thank you!
And thank you both for answering my question.
- Scribbles
- Miko-Class Veteran
- Posts: 636
- Joined: Wed Sep 21, 2016 4:15 pm
- Completed: Pinewood Island, As We Know It
- Projects: In Blood
- Organization: Jaime Scribbles Games
- Deviantart: breakfastdoodles
- itch: scribbles
- Location: Ohio
- Contact:
Re: Shuffle choice order
I really hate to dig up this old thread, but I can't get this to work for me :-/
in my functions code:
in screens.rpy:
it shuffles the order of the choices, but does it a few times before stopping and it's visible to the user/player. How can I have it done once without it being visible to the user/player?
it also doesn't remember that order during rollback and defaults to the original order as I defined under Menu in the script until I rollback past it, then it will revert to the original randomized order(after running through it a few times)
it's really just acting all kinds of crazy, and I can't find another simple method of doing this?
I just want every choice to display in a random order, though I would happily settle for defining when choices should display in a random order, and otherwise leaving the order as I've defined within the script alone.
Am I even making sense? I have not had my coffee yet I've been searching in google and on the forum but I can't find a solution that works? Unless I'm missing something?
ETA:
I've looked at:
https://www.renpy.org/doc/html/other.html#renpy-random
and
https://www.renpy.org/doc/html/screen_s ... tml#choice
but don't really see a solution there
in my functions code:
Code: Select all
init python:
def shuffle_items(items):
renpy.random.shuffle(items)
Code: Select all
screen choice(items):
$ shuffle_items(items)
style_prefix "choice"
vbox:
for i in items:
textbutton i.caption action i.action
it also doesn't remember that order during rollback and defaults to the original order as I defined under Menu in the script until I rollback past it, then it will revert to the original randomized order(after running through it a few times)
it's really just acting all kinds of crazy, and I can't find another simple method of doing this?
I just want every choice to display in a random order, though I would happily settle for defining when choices should display in a random order, and otherwise leaving the order as I've defined within the script alone.
Am I even making sense? I have not had my coffee yet I've been searching in google and on the forum but I can't find a solution that works? Unless I'm missing something?
ETA:
I've looked at:
https://www.renpy.org/doc/html/other.html#renpy-random
and
https://www.renpy.org/doc/html/screen_s ... tml#choice
but don't really see a solution there
- Divona
- Miko-Class Veteran
- Posts: 678
- Joined: Sun Jun 05, 2016 8:29 pm
- Completed: The Falconers: Moonlight
- Organization: Bionic Penguin
- itch: bionicpenguin
- Contact:
Re: Shuffle choice order
Here is what I did:
Code: Select all
default random_choices = False
screen choice(items):
style_prefix "choice"
python:
if random_choices == False:
renpy.random.shuffle(items)
random_choices = True
vbox:
for i in items:
textbutton i.caption action [SetVariable("random_choices", False), i.action]
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: Shuffle choice order
There was a Patreon post explaining how to do this last month...I imagine it is going to go live in the regular documentation soon?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3794
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Shuffle choice order
I imagine the error is similar to one I had a while back, but apparently variables in screens are not instant.
Don't know if it'll work with this or not, but have you tried using persistent instead? It fixed my issue.
Don't know if it'll work with this or not, but have you tried using persistent instead? It fixed my issue.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
- Scribbles
- Miko-Class Veteran
- Posts: 636
- Joined: Wed Sep 21, 2016 4:15 pm
- Completed: Pinewood Island, As We Know It
- Projects: In Blood
- Organization: Jaime Scribbles Games
- Deviantart: breakfastdoodles
- itch: scribbles
- Location: Ohio
- Contact:
Re: Shuffle choice order
this worked perfectly!Divona wrote: ↑Wed Sep 06, 2017 11:55 pm Here is what I did:
Code: Select all
default random_choices = False screen choice(items): style_prefix "choice" python: if random_choices == False: renpy.random.shuffle(items) random_choices = True vbox: for i in items: textbutton i.caption action [SetVariable("random_choices", False), i.action]
I need to check that site out, I've been meaning to but it keeps slipping my mind. I saw that he was offering tutorials as incentive, and I am all for that lol
I'm not sure how to adjust the choices to be persistents, but Divona's solution worked wonderfully so I'm pretty content with that lol. Though I'll still look over your post, I kinda know that variables in screens act a little fuzzy, but I don't know all the specificsImperf3kt wrote: ↑Thu Sep 07, 2017 1:12 am I imagine the error is similar to one I had a while back, but apparently variables in screens are not instant.
Don't know if it'll work with this or not, but have you tried using persistent instead? It fixed my issue.
Who is online
Users browsing this forum: Ocelot