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.
-
krt_org
- Newbie
- Posts: 13
- Joined: Wed Jul 04, 2018 7:48 pm
-
Contact:
#1
Post
by krt_org » Fri Aug 06, 2021 1:45 am
Hi! I'm having issues with random choice code that I want to use in my dating sim. I have a couple of different times in the dialogue you can have with the characters where I'd like the responses to be randomly generated. An example of the code I'm using is below:
Code: Select all
$ chance = renpy.random.randint(1,100)
if chance <= 100:
$ choice = renpy.random.choice(("8trivia1, 8trivia2, 8trivia3, 8trivia4"))
if choice == "8trivia1":
jump triv18
elif choice == "8trivia2":
jump triv28
elif choice == "8trivia3":
jump triv38
elif choice == "8trivia4":
jump triv48
else:
jump triv18
The issue with the code is that it doesn't seem to run the random choice, I get triv18 every single time. I had the "else: jump triv18" clause on there because I was thinking that you needed to have an else for an if, but I took it off (and deleted the persistent data) and I still always get the same choice. Is there something that needs to be changed to let it actually run a randomized choice every time? Is this intended to be only used once? The code would be run every time you talk to the character and select the trivia option.
I apologize if this question has been solved on the forum already; there were so many threads about random choice that didn't really seem to apply to what my issue is.
At the end of the day, I don't care much about randomization as much as I do that all the options have a chance to be displayed sometime.
I appreciate any help anyone has to offer! Thank you.
-
Ocelot
- Eileen-Class Veteran
- Posts: 1883
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
-
Contact:
#2
Post
by Ocelot » Fri Aug 06, 2021 4:45 am
See this:
Code: Select all
choice = renpy.random.choice
(
(
"8trivia1, 8trivia2, 8trivia3, 8trivia4"
)
)
Do you see the problem now? If you want more, add
$ print "choice: " + str(choice) after selecting random chice and after jump press Shift+O to see console putput.
Also, there is a more concise way to do what you want to do:
Code: Select all
$ choice = renpy.random.choice(("triv18", "triv28", "triv38", "triv48"))
jump expression choice
# Or even:
jump expression renpy.random.choice(("triv18", "triv28", "triv38", "triv48"))
< < insert Rick Cook quote here > >
Users browsing this forum: Google [Bot]