CREATE YOUR AI CUM SLUT ON CANDY.AI TRY FOR FREE
x

Ren'Py [Solved]random in renpy

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,131
3,195
how to make random event
Am I doing it right or wrong

default.rpy
Python:
default pregnacy = renpy.random.randint(1, 100)
script.rpy
Code:
 if pregnacy == 1:
        show ransi_jusei
        pause 2.0
        "Got her pregnate..."
        hide ransi_jusei
    elif pregnacy == 20:
        show ransi_jusei
        pause 2.0
        "Got her pregnate..."
        hide ransi_jusei
    elif pregnacy == 40:
        show ransi_jusei
        pause 2.0
        "Got her pregnate..."
        hide ransi_jusei
    elif pregnacy == 60:
        show ransi_jusei
        pause 2.0
        "Got her pregnate..."
        hide ransi_jusei
    elif pregnacy == 80:
        show ransi_jusei
        pause 2.0
        "Got her pregnate..."
        hide ransi_jusei
    elif pregnacy == 100:
        show ransi_jusei
        pause 2.0
        "Got her pregnate..."
        hide ransi_jusei
    elif pregnacy == 25:
        show ransi_jusei
        pause 2.0
        "Got her pregnate..."
        hide ransi_jusei
    elif pregnacy == 50:
        show ransi_jusei
        pause 2.0
        "Got her pregnate..."
        hide ransi_jusei
    elif pregnacy == 75:
        show ransi_jusei
        pause 2.0
        "Got her pregnate..."
        hide ransi_jusei
        hide ransi_jusei
    elif pregnacy == 100:
        show ransi_jusei
        pause 2.0
        "Got her pregnate..."
        hide ransi_jusei
    else:
        "Sorry you didn't get her pregnate..."
 
Last edited:

Cenc

Developing Reality
Game Developer
Jun 22, 2019
1,686
2,916
Essentially, though I don;t know if you really want to repeat the same code for each number that it lands on. consider instead a range:

For example, between 0 and 75 is a 'fail' or not pregnant state, whilst 76 to 100 would be a successful pregnancy. Its cleaner (code wise) and means you only need to keep track of 2 values.

Python:
if pregnancy in range (0, 75):
    show ransi_jusei
    pause 2.0
    "Your sperm is weak..."
    hide ransi_jusei
   
else:
    show ransi_jusei
    pause 2.0
    "Got her pregnant..."
    hide ransi_jusei
 
  • Like
Reactions: rayminator

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,259
Firstly, if you're wondering why if you rollback and go forward, you get the same result... it's a deliberate RenPy mechanism. It's random, but the random numbers are preselected - so the player can't just rollback and get a "better" answer. Same if you save and then load.
I doubt you meant that, but it's a common misunderstanding.

Next big one in my head... why default?
That makes it looks like the pregnancy value wouldn't change throughout the game. Surely you can't mean to set it once during game startup and then leave it as that value?

I'd expect something more like:

Python:
default pregnancy = 0

# ... later...

    $ pregnancy = renpy.random.randint(1, 100)
    if pregnancy ...

Next up, the value checks... are odd (and a lot of redundant duplication).
There are a lot more numbers between 1 and 100 than just 1, 20, 40, 60, 80, 100, 25, 50, 75 and (erm, 100 again?)

That's 9 numbers out of 100.

You could just as easily have done:

Python:
    $ pregnancy = renpy.random.randint(1, 100)
    if pregnancy >= 92:
        # pregnant code
    else:
        # not-pregnant code

Same 9 in 100 chance.
Except, now I'm questioning why 100? I mean it's a nice round number, and it's familiar... but...

9 out of 100 is almost the same as 10 out of 100. Which would be the same as 1 out of 10.

So wouldn't this be effectively the same?

Python:
    $ pregnancy = renpy.random.randint(1, 10)
    if pregnancy == 10:
        # pregnant code
    else:
        # not-pregnant code

If something about your game design DOES bring significance to the numbers 20, 40, etc... then this is an option too:

Python:
    $ pregnancy = renpy.random.randint(1, 100)
    if pregnancy in [1, 20, 25, 40, 50, 60, 75, 80, 100]:
        # pregnant code
    else:
        # not-pregnant code

I'm not suggesting use that code. I'm just suggesting think about why you're using those particular numbers. Do you want a 1 in 10 chance of getting pregnant? 1 in 20?
 
  • Like
Reactions: HB38 and rayminator