[SOLVED] My randInt script always displays the first possibility, no matter what Int the variable is

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
icecreamheadache
Newbie
Posts: 2
Joined: Wed Apr 18, 2018 3:56 pm
Contact:

[SOLVED] My randInt script always displays the first possibility, no matter what Int the variable is

#1 Post by icecreamheadache »

I know this is going to be the easiest solution. I'm new to ren'py and I think this is just a syntax issue.

What I'm trying to do is generate a random number, then depending on what it is, display different text to the user.

Code: Select all

$ r = renpy.random.randint(1,10)      #Generates the Int, stores it in the variable

if r==1,3:   #If the Int generated is 1, 2 or 3, display success
        "success"

else:        #if it is anything else, display fail
        "fail
"

I've tried so many variations of this code, such as

Code: Select all

elif r==4,5,6,7,8,9,10:
       "fail"
and pretty much any other way I've seen it written.

What happens is that it ALWAYS displays whatever the first block is, and then continues as told. I know it is generating a random number (I changed success to "[r]" to test this", it just doesn't seem to be actually checking what that number is at any point.

What am I doing wrong?
Last edited by icecreamheadache on Wed Apr 18, 2018 4:24 pm, edited 1 time in total.

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: My randInt script always displays the first possibility, no matter what Int the variable is

#2 Post by gas »

If r <4
If r> 3
Are the correct checks in that given case
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: My randInt script always displays the first possibility, no matter what Int the variable is

#3 Post by Remix »

Code: Select all

$ r = renpy.random.randint(1,10)      #Generates the Int, stores it in the variable

if 1 <= r <= 3:   #If the Int generated is 1, 2 or 3, display success
        "success"
elif r in [4,5,6]: # alternate comparison method
        "other success"
else:        #if it is anything else, display fail
        "fail"
Hopefully that will give you some ideas about python comparisons
Frameworks & Scriptlets:

icecreamheadache
Newbie
Posts: 2
Joined: Wed Apr 18, 2018 3:56 pm
Contact:

Re: My randInt script always displays the first possibility, no matter what Int the variable is

#4 Post by icecreamheadache »

gas wrote: Wed Apr 18, 2018 4:16 pm If r <4
If r> 3
Are the correct checks in that given case
Thanks so much! I've been looking all over, a lot of the other examples of this kind of code seem to be wrong.

Post Reply

Who is online

Users browsing this forum: piinkpuddiin