Setting possibilities/chance

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
User avatar
richycapy
Regular
Posts: 51
Joined: Mon May 27, 2019 8:53 pm
Organization: EN Productions
Location: Mexico
Contact:

Setting possibilities/chance

#1 Post by richycapy » Mon Sep 02, 2019 10:57 pm

Hi

Hope you are all doing great, I have a simple question... how can someone set possibilities/chances in the game, an example:

If the player does something in particular, set a 50% chance for a scene to apear, if the user doesn't do something in particular, set a 25% chance for a scene to apear

I hope is something simple to do :D

Thanks!! 8)

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3636
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Setting possibilities/chance

#2 Post by Imperf3kt » Mon Sep 02, 2019 11:40 pm

I use an RNG with a list of outcomes for this. Probably not the most elegant solution, but it works.

I can give you an example within a day or so.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

User avatar
Kia
Eileen-Class Veteran
Posts: 1011
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: Setting possibilities/chance

#3 Post by Kia » Tue Sep 03, 2019 1:06 am

the simple way is creating a temporary random value and compare.

Code: Select all

def chance_example():
    c = renpy.random.randint(0, 100)
    if chance_1 < c:
        # trigger the event

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

e

#4 Post by hell_oh_world » Tue Sep 03, 2019 3:15 am

richycapy wrote:
Mon Sep 02, 2019 10:57 pm
Hi

Hope you are all doing great, I have a simple question... how can someone set possibilities/chances in the game, an example:

If the player does something in particular, set a 50% chance for a scene to apear, if the user doesn't do something in particular, set a 25% chance for a scene to apear

I hope is something simple to do :D

Thanks!! 8)
In addition to what Kia said, you could also do it like this, I guess...

Code: Select all

default userdidSomething = False
default probability = renpy.random.random()
if probability >= 0.50 and userdidSomething:
	do something...
elif probability <= 0.25 and not userdidSomething:
	do something...

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Setting possibilities/chance

#5 Post by isobellesophia » Tue Sep 03, 2019 9:57 am

richycapy wrote:
Mon Sep 02, 2019 10:57 pm
Hi

Hope you are all doing great, I have a simple question... how can someone set possibilities/chances in the game, an example:

If the player does something in particular, set a 50% chance for a scene to apear, if the user doesn't do something in particular, set a 25% chance for a scene to apear

I hope is something simple to do :D

Thanks!! 8)


You could also try this one, just found it on google.

viewtopic.php?t=25769#p315831
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3636
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Setting possibilities/chance

#6 Post by Imperf3kt » Tue Sep 03, 2019 3:59 pm

Imperf3kt wrote:
Mon Sep 02, 2019 11:40 pm
I use an RNG with a list of outcomes for this. Probably not the most elegant solution, but it works.

I can give you an example within a day or so.
The way I'm doing it isn't much different from how Kia suggested, but I'll post it anyway since I have it here.

Code: Select all

default result = 0

label start:
    $ result = renpy.random.randint(1, 16)
    if result in [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]:
        # 100% chance
    elif result == 0 or is > 16:
        "ERROR" 
        
to get a specific chance value, omit some of the numbers in the list, for example, removing half of them gives a 50% chance of renpy.random creating an integer in the list.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

Post Reply

Who is online

Users browsing this forum: Bing [Bot]