Page 1 of 1

Setting possibilities/chance

Posted: Mon Sep 02, 2019 10:57 pm
by richycapy
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)

Re: Setting possibilities/chance

Posted: Mon Sep 02, 2019 11:40 pm
by Imperf3kt
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.

Re: Setting possibilities/chance

Posted: Tue Sep 03, 2019 1:06 am
by Kia
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

e

Posted: Tue Sep 03, 2019 3:15 am
by hell_oh_world
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...

Re: Setting possibilities/chance

Posted: Tue Sep 03, 2019 9:57 am
by isobellesophia
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

Re: Setting possibilities/chance

Posted: Tue Sep 03, 2019 3:59 pm
by Imperf3kt
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.