DICE ROLL and if statements

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
Timberduck
Regular
Posts: 60
Joined: Sat Jan 04, 2014 12:52 am
Location: Canada
Contact:

DICE ROLL and if statements

#1 Post by Timberduck »

I want to do a dice roll
and the result activates an if statement:

1-10 activates if statement A
11-20 activates if statement B'




\m/Timberduck\m/

seitensei
Newbie
Posts: 9
Joined: Wed Jan 22, 2014 1:15 pm
Contact:

Re: DICE ROLL and if statements

#2 Post by seitensei »

You should be able to achieve that through normal conditionals and a random integer. It shouldn't require any changes or additions to Ren'Py.

Don't remember the syntax off the top of my head, but python has randint-
dice = randint(1,11)
if dice <= 10
statement a

Timberduck
Regular
Posts: 60
Joined: Sat Jan 04, 2014 12:52 am
Location: Canada
Contact:

Re: DICE ROLL and if statements

#3 Post by Timberduck »

Cool thanks
I just need to play around with it.
XD

Timberduck
Regular
Posts: 60
Joined: Sat Jan 04, 2014 12:52 am
Location: Canada
Contact:

Re: DICE ROLL and if statements

#4 Post by Timberduck »

actually my problem is displying the number i keep getting error messages and have no clue what is the issue.

Timberduck
Regular
Posts: 60
Joined: Sat Jan 04, 2014 12:52 am
Location: Canada
Contact:

Dice roll #2

#5 Post by Timberduck »

I am trying to get Dice roll to work
my problem is displaying the roll.
I have spent a few hours already and I am just about to defenestrate my computer into my monitor.

just need an answer.


\m/Timberduck\m/

LVUER
King of Lolies
Posts: 4538
Joined: Mon Nov 26, 2007 9:57 pm
Completed: R.S.P
Location: Bandung, West Java, Indonesia
Contact:

Re: DICE ROLL and if statements

#6 Post by LVUER »

This is a question about how to use RenPy. I move it to RenPy Questions and Announcements.

I also merge the topic. You don't need to make a new thread to ask same question.

Also, please be patient. It hasn't even been one hour since you last ask your question. Everyone have a life out there and not to mention this is an international forum.
"Double the princesses, quadruple the fun!" - Haken Browning (SRW-OG Endless Frontier)

DeviantArt Account
MoeToMecha Blog (under construction)
Lolicondria Blog (under construction) <- NSFW

Timberduck
Regular
Posts: 60
Joined: Sat Jan 04, 2014 12:52 am
Location: Canada
Contact:

Re: DICE ROLL and if statements

#7 Post by Timberduck »

Sorry,

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Dice roll #2

#8 Post by xela »

Timberduck wrote:I am trying to get Dice roll to work
my problem is displaying the roll.
I have spent a few hours already and I am just about to defenestrate my computer into my monitor.

just need an answer.


\m/Timberduck\m/
Something I've used in the past:

Code: Select all

def dice(value, limit=100, show=True):
        '''Returns True if value is <= a random integer between 1 and limit.

        If limit is 100, this means that a value of 60 has a 60% chance for True
        '''
        number = random.randint(1, limit)
        if number <= value:
            result = True
        else:
            result = False
        if config.developer and show:
            renpy.notify(u"Resulted in %d from %d, limit - %d, and result - %s." % (number, limit, value, result))
        return result
was abandoned in favor of:

Code: Select all

    def dice(value):
        """Randomly generated percentage chance to return a bool"""
        return (value / 100.0) > random.random()
as calling dice with notify few hundred times in a raw made Ren'Py really sluggish.
Like what we're doing? Support us at:
Image

Timberduck
Regular
Posts: 60
Joined: Sat Jan 04, 2014 12:52 am
Location: Canada
Contact:

Re: DICE ROLL and if statements

#9 Post by Timberduck »

Thanks for your help just one last thing
expected statement.
def dice(value):
^
anyway to cure this ?

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: DICE ROLL and if statements

#10 Post by xela »

Timberduck wrote:Thanks for your help just one last thing
expected statement.
def dice(value):
^
anyway to cure this ?
Oh, it's python, you have to put this in init python:

Without showing results:

Code: Select all

init -10 python: 

    def dice(value):
        """Randomly generated percentage chance to return a bool"""
        return (value / 100.0) > random.random()
Like what we're doing? Support us at:
Image

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot], Sugar_and_rice, voluorem