Hello, using another forum on this site I managed to get the following code to work, but I'm not sure how to assign multiple numbers to the outcomes (or if even possible). What I would like to do is assign numbers ranging from 1 to 100 divided among each so I can make some more common/rare than the others (i.e. little sister at 30%, mother at 40%, older sister at 25%, successfully sneaking out at the remaining 5%). I'm sure this is a simple fix/thing to do. Just really new to this coding thing (picked it up maybe two-ish weeks ago). So please and thank you for your help!
label encounter1:
Nar "You double check to make sure you have everything. Phone, car keys, wallet, etc."
$ sneakoutattemt = 0
$ sneakoutattemt = "none"
$ sneakoutattemt = renpy.random.randint(1,5)
if sneakoutattemt == 1:
$ sneakoutattemttext = "You turn around and see your little sister, Faith standing in the doorway."
Nar "[sneakoutattemttext]"
jump encounterfaith
if sneakoutattemt == 2:
$ sneakoutattemttext = "Your mother catches you!"
Nar "[sneakoutattemttext]"
if sneakoutattemt == 3:
$ sneakoutattemttext = "Your older sister approaches!"
Nar "[sneakoutattemttext]"
jump encounterclaire
if sneakoutattemt == 4:
$ sneakoutattemttext = "You get to your car safely"
Nar "[sneakoutattemttext]"
Random Event Help [solved]
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.
-
- Newbie
- Posts: 7
- Joined: Tue Jun 06, 2017 10:05 am
- Contact:
Random Event Help [solved]
Last edited by PhoenixianUltima on Tue Jul 04, 2017 4:12 pm, edited 1 time in total.
- 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: Random Event Help
Code: Select all
label encounter1:
Nar "You double check to make sure you have everything. Phone, car keys, wallet, etc."
$ sneakoutattemt = renpy.random.randint(0.0, 1.0)
## Mother at 40% ( 100% - 40% = 60% ).
## If more than 60%, meet mother.
if sneakoutattemt > 0.6:
$ sneakoutattemttext = "Your mother catches you!"
Nar "[sneakoutattemttext]"
## Little sister at 30% ( 100% - 40% - 30% = 30% ).
## If more than 30%, meet sister.
elif sneakoutattemt > 0.3:
$ sneakoutattemttext = "You turn around and see your little sister, Faith standing in the doorway."
Nar "[sneakoutattemttext]"
jump encounterfaith
## Older sister at 25% ( 100% - 40% - 30% - 25% = 5% ).
## If more than 5%, meet older sister.
elif sneakoutattemt > 0.05:
$ sneakoutattemttext = "Your older sister approaches!"
Nar "[sneakoutattemttext]"
jump encounterclaire
## Successfully sneaking out at reminding 5%.
else:
$ sneakoutattemttext = "You get to your car safely"
Nar "[sneakoutattemttext]"
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Random Event Help
... or ...
Should work
Suggest using a divide by 5 on the values though, so 6, 8, 5, 1 rather than the big numbers.
It basically expands the dict to a list whereby each value is repeated by the key number then chooses one from that list randomly
Code: Select all
label start:
python:
# likelihood : speak text, jump label
sneak_opts = {
30 : ("You turn around and see your little sister, Faith standing in the doorway.", "encounterfaith"),
40 : ("Your mother catches you!", "encountermum"),
25 : ("Your older sister approaches!", "encounterclaire"),
5 : ("You get to your car safely", "mycarlabel")
}
sneak_text, sneak_jump = renpy.random.choice([y for x in [[sneak_opts[i]]*i for i in sneak_opts] for y in x])
Nar "[sneak_text]"
"Would jump to [sneak_jump]"
# jump expression sneak_jump
Suggest using a divide by 5 on the values though, so 6, 8, 5, 1 rather than the big numbers.
It basically expands the dict to a list whereby each value is repeated by the key number then chooses one from that list randomly
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
-
- Newbie
- Posts: 7
- Joined: Tue Jun 06, 2017 10:05 am
- Contact:
Re: Random Event Help
Tried this multiple times but all it seems to put out are the first and last options, not getting the middle two at all ....Divona wrote:Code: Select all
label encounter1: Nar "You double check to make sure you have everything. Phone, car keys, wallet, etc." $ sneakoutattemt = renpy.random.randint(0.0, 1.0) ## Mother at 40% ( 100% - 40% = 60% ). ## If more than 60%, meet mother. if sneakoutattemt > 0.6: $ sneakoutattemttext = "Your mother catches you!" Nar "[sneakoutattemttext]" ## Little sister at 30% ( 100% - 40% - 30% = 30% ). ## If more than 30%, meet sister. elif sneakoutattemt > 0.3: $ sneakoutattemttext = "You turn around and see your little sister, Faith standing in the doorway." Nar "[sneakoutattemttext]" jump encounterfaith ## Older sister at 25% ( 100% - 40% - 30% - 25% = 5% ). ## If more than 5%, meet older sister. elif sneakoutattemt > 0.05: $ sneakoutattemttext = "Your older sister approaches!" Nar "[sneakoutattemttext]" jump encounterclaire ## Successfully sneaking out at reminding 5%. else: $ sneakoutattemttext = "You get to your car safely" Nar "[sneakoutattemttext]"
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Random Event Help
randint outputs an integer, so could only do zero or one, hence first or last
Maybe use randint(0, 100) and recode the tests againt 100... e.g. > 60 rather than > 0.6
... or try my suggested code
Maybe use randint(0, 100) and recode the tests againt 100... e.g. > 60 rather than > 0.6
... or try my suggested code
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
-
- Newbie
- Posts: 7
- Joined: Tue Jun 06, 2017 10:05 am
- Contact:
Re: Random Event Help
Alright, changing it like that did work. Thank you.Remix wrote:randint outputs an integer, so could only do zero or one, hence first or last
Maybe use randint(0, 100) and recode the tests againt 100... e.g. > 60 rather than > 0.6
... or try my suggested code
And would've tried your code, but I wanted to keep the roll in the background/secret and with yours it didn't seem like I could make it jump without bringing up the 'confirm' action to progress it.
Who is online
Users browsing this forum: Google [Bot], mirceea