Random Event Help [solved]

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.
Post Reply
Message
Author
PhoenixianUltima
Newbie
Posts: 7
Joined: Tue Jun 06, 2017 10:05 am
Contact:

Random Event Help [solved]

#1 Post by PhoenixianUltima »

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]"
Last edited by PhoenixianUltima on Tue Jul 04, 2017 4:12 pm, edited 1 time in total.

User avatar
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

#2 Post by Divona »

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]"
Completed:
Image

User avatar
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

#3 Post by Remix »

... or ...

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
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
Frameworks & Scriptlets:

PhoenixianUltima
Newbie
Posts: 7
Joined: Tue Jun 06, 2017 10:05 am
Contact:

Re: Random Event Help

#4 Post by PhoenixianUltima »

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]"
Tried this multiple times but all it seems to put out are the first and last options, not getting the middle two at all ....

User avatar
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

#5 Post by Remix »

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 ;)
Frameworks & Scriptlets:

PhoenixianUltima
Newbie
Posts: 7
Joined: Tue Jun 06, 2017 10:05 am
Contact:

Re: Random Event Help

#6 Post by PhoenixianUltima »

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 ;)
Alright, changing it like that did work. Thank you.

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.

Post Reply

Who is online

Users browsing this forum: Google [Bot], mirceea