Random chance test [Solved]

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
Stapper
Regular
Posts: 96
Joined: Wed Feb 27, 2013 9:54 pm
Contact:

Random chance test [Solved]

#1 Post by Stapper » Wed Mar 19, 2014 11:49 am

I would like to implement a random chance test in my game depending on the stats and gear of the player. I have calculated their chance and save it as: $ chance_number

Now they have chance_number out of 10 to pass the test. How can I calculate this? I thought about using the renpy.random.randint function, but I don't know how to use it to see if they would pass the actual test.

Can anyone please show me how to do this :)
Last edited by Stapper on Wed Mar 19, 2014 12:53 pm, edited 1 time in total.

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Random chance test

#2 Post by Alex » Wed Mar 19, 2014 12:14 pm

Try

Code: Select all

label start:
    $ chance_number = 7
    if chance_number >= renpy.random.randint(1, 10):
        "Win"
    else:
        "Lose"
    jump start
http://www.renpy.org/wiki/renpy/doc/ref ... om.randint

User avatar
Stapper
Regular
Posts: 96
Joined: Wed Feb 27, 2013 9:54 pm
Contact:

Re: Random chance test

#3 Post by Stapper » Wed Mar 19, 2014 12:53 pm

Seems to works perfectly :D

Thanks again Alex!

Post Reply

Who is online

Users browsing this forum: Bing [Bot]