Page 1 of 1

Checking multiple numbers in "If" statement

Posted: Sat Apr 11, 2020 12:16 pm
by FunbagsGP
Hi, I'm working on a really basic roulette minigame where you can basically choose Red or Black. I have it almost finished, with the exception of one problem. I cannot seem to get it to accurately check if a certain set of numbers are Red or Black, it's like it skips it entirely. I'm sure there is an easier way of coding that particular part as it feels a little goofy the way I've got it currently coded. I searched around the forums and was unable to find anything specific enough to help out, so I thought maybe you guys could take a look:

The part of the code I'm having issues with:

Code: Select all

            if rouletteroll == 2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33 or 35:
                $colorroll = "Black"
            if rouletteroll == 1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34 or 36:
                $colorroll = "Red"
and essentially it's running a renpy.random.randint(0,36) beforehand, and afterwards stating to the player if they won or not. I can post the entire code if needed, but since this is the part I'm having problems with I thought I would start there. Thanks!

EDIT: I forgot to post what the actual issue is that it's doing, it's basically going by which ever one I've got coded last as permanently the color. For example with the code above it'll state that the player rolled a Red 2, which is inaccurate. Hope that helps!

Re: Checking multiple numbers in "If" statement

Posted: Sat Apr 11, 2020 12:54 pm
by Per K Grok
FunbagsGP wrote:
Sat Apr 11, 2020 12:16 pm
Hi, I'm working on a really basic roulette minigame where you can basically choose Red or Black. I have it almost finished, with the exception of one problem. I cannot seem to get it to accurately check if a certain set of numbers are Red or Black, it's like it skips it entirely. I'm sure there is an easier way of coding that particular part as it feels a little goofy the way I've got it currently coded. I searched around the forums and was unable to find anything specific enough to help out, so I thought maybe you guys could take a look:

The part of the code I'm having issues with:

Code: Select all

            if rouletteroll == 2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33 or 35:
                $colorroll = "Black"
            if rouletteroll == 1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34 or 36:
                $colorroll = "Red"
and essentially it's running a renpy.random.randint(0,36) beforehand, and afterwards stating to the player if they won or not. I can post the entire code if needed, but since this is the part I'm having problems with I thought I would start there. Thanks!

EDIT: I forgot to post what the actual issue is that it's doing, it's basically going by which ever one I've got coded last as permanently the color. For example with the code above it'll state that the player rolled a Red 2, which is inaccurate. Hope that helps!
Try this

Code: Select all


label start:

    $ rouletteroll=renpy.random.randint(0,36)

    if rouletteroll in [2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35]:
        $ colorroll = "Black"
    elif rouletteroll==0:
        $ colorroll = ""
    else:
        $ colorroll = "Red"

    "[colorroll] [rouletteroll]"


    jump start



Re: Checking multiple numbers in "If" statement

Posted: Sat Apr 11, 2020 1:20 pm
by FunbagsGP
Thank you so much! This worked!