So i've just started using Ren'Py. Not doing too badly, though i've never really done any programming so its all completely new to me. I can do basic dialogue, image insertion and movement as well as menu's and such. The very basics. The next thing i want to try and achieve is a menu with options that result in randomly selected outcomes.
Example:
Situation is the character gets confronted.
Normal menu would be along the lines of:
Walk away - leads to walking away
Punch - leads to fight
What I would like to do is more along the lines of:
Walk away - 50% chance of being followed and 50% chance of getting away.
punch - 50% chance of knocking the other guy out and 50% chance of getting knocked out.
I've looked for a cookbook recepie to help me out and googled it, but i've not found anything I can make sense of. I'm hoping someone here might be able to help me. Please bear in mind i'm a complete beginner though. Thanks for any help
How do I question: Random results from a menu selection
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.
- Evildumdum
- Regular
- Posts: 191
- Joined: Sun Jan 18, 2015 8:49 am
- Projects: ApoclypseZ
- Contact:
- xavimat
- Eileen-Class Veteran
- Posts: 1461
- Joined: Sat Feb 25, 2012 8:45 pm
- Completed: Yeshua, Jesus Life, Cops&Robbers
- Projects: Fear&Love
- Organization: Pilgrim Creations
- Github: xavi-mat
- itch: pilgrimcreations
- Location: Spain
- Discord: xavimat
- Contact:
Re: How do I question: Random results from a menu selection
Let's separate the two questions here.
1. You say you can do a normal menu. Perfect.
2. The random question has nothing to do with menus. You can use a random function and the "if" statement.
Of course you can add this code INSIDE the menu (as you can add any other block of code there) but my point is that the random question has its own solution. Doesn't matter if you're using it with or without menus.
1. You say you can do a normal menu. Perfect.
2. The random question has nothing to do with menus. You can use a random function and the "if" statement.
Code: Select all
label try_to_walk_away:
$ r = renpy.random.randint(1,2) # This will set "r" to 1 or 2 randomly
if r == 1:
jump walk_away
else:
jump can_not_walk_away
Last edited by xavimat on Sun Jan 18, 2015 10:07 am, edited 1 time in total.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)
- Evildumdum
- Regular
- Posts: 191
- Joined: Sun Jan 18, 2015 8:49 am
- Projects: ApoclypseZ
- Contact:
Re: How do I question: Random results from a menu selection
Thank you, that little piece of code really helped me out.
- Evildumdum
- Regular
- Posts: 191
- Joined: Sun Jan 18, 2015 8:49 am
- Projects: ApoclypseZ
- Contact:
Re: How do I question: Random results from a menu selection
I've experimented a little with it. Its seems that it can only make a choice between 1 and 2 each having an equal chance of being chosen. It's possible to use multiple layers of 50/50 chances to create a scenario where one outcome is more likely than another, but it's a bit of a pain and makes 1 in 10 chances or 3 or more outcomes needlessly complicated. You'll probably see what i was trying to do if i show you a bit of code i experimented with and failed. You'll have to pardon the way it's pasted. all the indentations are correct in the code, but i haven't worked out how to paste it like you have.
label skip1:
"Right, time for experimenting."
menu:
"Lets go ride a pig":
jump pig1
"Lets go pet a bunny rabbit":
jump bunny1
"Boring. Skip":
jump carry_on2
label pig1:
$ r = renpy.random.randint(1,2,3,4,5,6)
if r == 1,2,3:
"The pig ride is super fun."
jump carry_on2
if r == 4,5:
"The pig throws you to the ground and you get muddy"
jump dead_end
if r == 6:
"The pig kills you on the spot with its super nuzzle."
jump generic_bad_end
Needless to say that didn't work. I came up with a way to work it, but it's not ideal as you'll see below.
label skip1:
"Right, time for experimenting."
menu:
"Lets go ride a pig":
jump pig1
"Lets go pet a bunny rabbit":
jump bunny1
"Boring. Skip":
jump carry_on2
label pig1:
$ r = renpy.random.randint(1,2)
if r == 1:
"The pig ride is super fun."
jump carry_on2
if r == 2:
"The pig throws you to the ground and you get muddy"
$ r = renpy.random.randint(1,2)
if r == 1:
"The pig kills you on the spot with its super nuzzle."
jump dead_end
if r == 2:
"you're muddy and cold. Go home."
jump generic_bad_end
label skip1:
"Right, time for experimenting."
menu:
"Lets go ride a pig":
jump pig1
"Lets go pet a bunny rabbit":
jump bunny1
"Boring. Skip":
jump carry_on2
label pig1:
$ r = renpy.random.randint(1,2,3,4,5,6)
if r == 1,2,3:
"The pig ride is super fun."
jump carry_on2
if r == 4,5:
"The pig throws you to the ground and you get muddy"
jump dead_end
if r == 6:
"The pig kills you on the spot with its super nuzzle."
jump generic_bad_end
Needless to say that didn't work. I came up with a way to work it, but it's not ideal as you'll see below.
label skip1:
"Right, time for experimenting."
menu:
"Lets go ride a pig":
jump pig1
"Lets go pet a bunny rabbit":
jump bunny1
"Boring. Skip":
jump carry_on2
label pig1:
$ r = renpy.random.randint(1,2)
if r == 1:
"The pig ride is super fun."
jump carry_on2
if r == 2:
"The pig throws you to the ground and you get muddy"
$ r = renpy.random.randint(1,2)
if r == 1:
"The pig kills you on the spot with its super nuzzle."
jump dead_end
if r == 2:
"you're muddy and cold. Go home."
jump generic_bad_end
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: How do I question: Random results from a menu selection
I like renpy.random.random(), which returns a random number between 0 and 1. so you can have:
I'm not sure VN players are a fan of randomness in general, especially random bad ends.
Code: Select all
$ r = renpy.random.random()
if r < 3.0 / 6.0:
"The pig ride is super fun."
jump carry_on2
elif r < 5.0 / 6.0:
"The pig throws you to the ground and you get muddy"
jump dead_end
else:
"The pig kills you on the spot with its super nuzzle."
jump generic_bad_end
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
- Evildumdum
- Regular
- Posts: 191
- Joined: Sun Jan 18, 2015 8:49 am
- Projects: ApoclypseZ
- Contact:
Re: How do I question: Random results from a menu selection
Thank you, I'll try this one
As for random bad endings in VN's, it was only a random scenario to test the mechanics. I'm actually using ren'py because i want to make a game that is more like a visual strategy game. I'm still learning the basics, but random events would be a big part of it. The next step is learning how to programme character attached stats and combine them with the event probability or outcomes. Its going to get very complicated i'm sure, but I have to start somewhere lol.
As for random bad endings in VN's, it was only a random scenario to test the mechanics. I'm actually using ren'py because i want to make a game that is more like a visual strategy game. I'm still learning the basics, but random events would be a big part of it. The next step is learning how to programme character attached stats and combine them with the event probability or outcomes. Its going to get very complicated i'm sure, but I have to start somewhere lol.
- xavimat
- Eileen-Class Veteran
- Posts: 1461
- Joined: Sat Feb 25, 2012 8:45 pm
- Completed: Yeshua, Jesus Life, Cops&Robbers
- Projects: Fear&Love
- Organization: Pilgrim Creations
- Github: xavi-mat
- itch: pilgrimcreations
- Location: Spain
- Discord: xavimat
- Contact:
Re: How do I question: Random results from a menu selection
I forgot to explain the function and to point to the doc: http://www.renpy.org/doc/html/other.html#renpy-random
We have
renpy.random.randint(a, b) -> returns a random (integer) number between 'a' and 'b'.
renpy.random.random()
renpy.random.choice(seq) -> choices an element in 'seq' (for example, from a list)
We have
renpy.random.randint(a, b) -> returns a random (integer) number between 'a' and 'b'.
renpy.random.random()
renpy.random.choice(seq) -> choices an element in 'seq' (for example, from a list)
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)
Who is online
Users browsing this forum: Google [Bot]