Randomizing Outcomes? (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
Lotus
Veteran
Posts: 298
Joined: Thu Jan 06, 2011 9:28 am
Projects: Unnamed Slenderman VN, Secret 10560
Location: USA
Contact:

Randomizing Outcomes? (Solved)

#1 Post by Lotus »

I'm not sure how to phrase the title and my situation, sorry! ><

Basically what I have in mind is that there is a menu in the game with a "run away" option; when the player clicks on "run away", what will take place after that will be randomized so that you may not get the same route twice (either the player runs into a bad guy or the player runs into her friend who saves her from the bad guy). I was also wanting to make it so that if the player talked to the friend before this event, they would have a higher chance of getting the route with the friend. I have no idea how to code this, help is very much appreciated C:
Last edited by Lotus on Wed Mar 02, 2011 1:23 pm, edited 1 time in total.

Black_Saber
Regular
Posts: 74
Joined: Wed Jul 14, 2010 4:56 am
Completed: cafe minigame
Projects: Beach Restaurant
Location: Indonesia
Contact:

Re: Randomizing Outcomes?

#2 Post by Black_Saber »

Do you mean like this?

Code: Select all

    $ event = renpy.random.choice(['random1', 'random2', 'random3', 'random4', 'random5'])
    menu:
        "go to the left":
                jump left
        "run away":
                $ renpy.jump(event)

label left:
   "text goes here"
label random1:
   "text goes here"

--- you can figure out the rest ---


for a percentage of higher chance to get certain event, I don't know about that.
"*cackle*cackle*! In short, it's all about cleverly using the gaps between jobs to play. If it goes too far, it can turn to laziness. However, people only become mature when they learn to balance work with pleasure. Simply put, if all you care about is work all the time, you're not fully mature." - Gaap (Umineko no Naku Koro ni)

Lotus
Veteran
Posts: 298
Joined: Thu Jan 06, 2011 9:28 am
Projects: Unnamed Slenderman VN, Secret 10560
Location: USA
Contact:

Re: Randomizing Outcomes?

#3 Post by Lotus »

I think that's sort of what I want, though I still need the code for increasing the chances of getting one over the other. Thank you for that code though c: That does help a little.

Edit: Will this work for what I need? http://www.renpy.org/wiki/renpy/doc/coo ... han_others

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: Randomizing Outcomes?

#4 Post by Aleema »

I just use:

Code: Select all

num = renpy.random.randint(0,100)
if num <= 25:
#25% chance option#
else:
#75% chance option#

User avatar
Alera
Miko-Class Veteran
Posts: 651
Joined: Sun Mar 21, 2010 3:20 am
Completed: Tortichki // Zayay // Hero's Spirit
Deviantart: psyalera
itch: psyalera
Location: UK
Contact:

Re: Randomizing Outcomes?

#5 Post by Alera »

Oh, what Aleema said sounds really easy! ^^

Another thought I had is just to make more labels that lead to the same place? 'random1'-goes to 1 point of the sotry you want and lets say 'random2 and 3' go to a second! You have 1:2 chances now. XD

But yeah- better try Aleema's way. ;'D
Image
Games:
❤️ Zayay [Otome?][BxPlayer][NaNo 2013]
❤️ Tortichki [Drag&Drop mini game]

Other games I've worked on:
My Heart's Flame Emissary of Starlight Freedom From Silence Sickness
And many more unannounced/secret projects. (. .)

Black_Saber
Regular
Posts: 74
Joined: Wed Jul 14, 2010 4:56 am
Completed: cafe minigame
Projects: Beach Restaurant
Location: Indonesia
Contact:

Re: Randomizing Outcomes?

#6 Post by Black_Saber »

Aleema wrote:I just use:

Code: Select all

num = renpy.random.randint(0,100)
if num <= 25:
#25% chance option#
else:
#75% chance option#
waw, this was great!

thanks for the knowledge, Aleema.
"*cackle*cackle*! In short, it's all about cleverly using the gaps between jobs to play. If it goes too far, it can turn to laziness. However, people only become mature when they learn to balance work with pleasure. Simply put, if all you care about is work all the time, you're not fully mature." - Gaap (Umineko no Naku Koro ni)

Lotus
Veteran
Posts: 298
Joined: Thu Jan 06, 2011 9:28 am
Projects: Unnamed Slenderman VN, Secret 10560
Location: USA
Contact:

Re: Randomizing Outcomes?

#7 Post by Lotus »

Thanks a bunch for that, Aleema! I still don't know how to do this
I was also wanting to make it so that if the player talked to the friend before this event, they would have a higher chance of getting the route with the friend.
but would that be done with an if code? Like this:

Code: Select all

if friend_meeting:
    num = renpy.random.randint(0,100)
    if num <= 25:
    #25% chance option#
    else:
    #75% chance option#
else:
    num = renpy.random.randint(0,100)
    if num <= 50:
    #50% chance option#
    else:
    #50% chance option#
Also, is anyone else having troubles with apostrophes? I wasn't having any problems yesterday, then I checked my script today and they messed up! D: I tried the backslash trick but it didn't work.Never mind on that, it seems to have fixed itself. I guess it was because I accidentally left out a " at the end of a line. D'oh!

Lotus
Veteran
Posts: 298
Joined: Thu Jan 06, 2011 9:28 am
Projects: Unnamed Slenderman VN, Secret 10560
Location: USA
Contact:

Re: Randomizing Outcomes?

#8 Post by Lotus »

Sorry for double posting, but I just tried the code you suggested for the random outcomes and it gave me an error.

Here's the code I used

Code: Select all

menu:
        "Run.":
            "I ran."
            num = renpy.random.randint(0,100) ##This is line 110
            if num <= 25:
                jump run1
            else:
                jump run2
and here's the error

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


On line 110 of G:\Lauren\Beauty and Beast/game/script.rpy: expected statement.
num = renpy.random.randint(0,100)
    ^

Ren'Py Version: Ren'Py 6.12.0e

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: Randomizing Outcomes?

#9 Post by Aleema »

You need to put a $ sign in front of it when you're not in python.

Code: Select all

$ num = renpy.random.randint(0,100)

Lotus
Veteran
Posts: 298
Joined: Thu Jan 06, 2011 9:28 am
Projects: Unnamed Slenderman VN, Secret 10560
Location: USA
Contact:

Re: Randomizing Outcomes?

#10 Post by Lotus »

D'oh! Thanks for the fast response Aleema. C:

Post Reply

Who is online

Users browsing this forum: No registered users