Random Number Won't Reroll

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
Galxy Games
Newbie
Posts: 11
Joined: Sun Sep 10, 2017 7:30 pm
Organization: Galxy Studios
Deviantart: GalxyStudios
Contact:

Random Number Won't Reroll

#1 Post by Galxy Games »

I can't get the random integer to reroll. I tried both jumping to and calling this from the player's turn (which also has the same issue)

Code: Select all

label enemy_turn:
    if enemy_health > 0:
        if enemy_type == "Slime":
            $ d6 = renpy.random.randint(1,6)
            if d6 == 5 or 6:
                $ d6 = renpy.random.randint(2,6)
                "The Slime's acid burns you."
                label enemydone:
                    $ enemy_attack = d6
                    $ health -= enemy_attack
                    "It does %(enemy_attack)s damage."
                    call yourturn
            elif d6 == 2:
                "The slime misses it's attack"
            else:
                "The Slime lunges with its teeth"
                $ d6 = renpy.random.randint(1,4)
                jump enemydone
        elif enemy_type == "RatCat":
            $ d6 = renpy.random.randint(1,6)
            if d6 == 5 or 6:
                "The ratcat's teeth sink into you."
                $ d6 = renpy.random.randint(3,7)
                jump enemydone
            elif d6 == 2 or 3:
                "The Ratcat misses it's attack"
            else:
                $ d6 = renpy.random.randint(2,4)
                "The ratcat swipes with its claws"
                jump enemydone
        elif enemy_type == "Rock Crab":
            $ d6 = renpy.random.randint(1,6)
            if d6 == 5 or 6:
                "The rock crab bodyslams you."
                $ d6 = renpy.random.randint(6,7)
                jump enemydone
            elif d6 == 2 or 3:
                "The rock crab misses it's attack"
            else:
                $ d6 = renpy.random.randint(4,5)
                "The rock crab pinches you."
                jump enemydone

    else:
        "The foe was vanished."
        call area_after

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Random Number Won't Reroll

#2 Post by PyTom »

d6 == 5 or 6

Isn't correct. It is _valid_ Python, which is why the game runs. But parenthesized, it reads:

(d6 == 5) or 6

Since 6 is non-zero, it's true, and this will always be true.

Yo probably want to write:

(d6 == 5) or (d6 == 6)

and similar for the 2 or 3 construct.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
m_from_space
Miko-Class Veteran
Posts: 975
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Random Number Won't Reroll

#3 Post by m_from_space »

And you could also write...

Code: Select all

if d6 > 4:
    ...
    
# or

if d6 in [5, 6]:
    ...

Post Reply

Who is online

Users browsing this forum: No registered users