Page 1 of 1
persistant random number generator, how to?
Posted: Thu Dec 20, 2018 6:52 pm
by VorrAkkagi
Hi all,
I'm wondering what is the best way to create and call a random number generator and how to properly use it. I'm currently using this code:
$ d20roll = renpy.random.randint(1, 20) #this is what I want to call
menu: #this is what I've hacked together. Been looking all over for example of how to do this properly with no luck =/
"Peek in the front window":
$ d20roll
if d20roll > 15:
$ sneek +=1
jump frontdoor
"Walk in and see first hand":
jump frontdoor
And can someone point out to me to properly post code here please? I don't know the method...
Re: persistant random number generator, how to?
Posted: Fri Dec 21, 2018 9:39 am
by DannX
To post code here, make use of the
[code] and
[/code] tags, like this:
[code]
Paste your code here
[/code]
As for your question, I'm not sure I understand correctly, but each time you want to roll the dice, you call the function again.
Code: Select all
menu:
"Peek in the front window":
$ d20roll = renpy.random.randint(1,20) #this sets d20roll to a new value between 1 and 20.
if d20roll > 15:
$ sneek +=1
jump frontdoor
Re: persistant random number generator, how to?
Posted: Fri Dec 21, 2018 2:47 pm
by VorrAkkagi
Ah thanks for the code pasting info! =)
So quick question. I have defined the d20 roll at the top of my code with other defines using the '$' in this case. Are you saying this will keep the same value unless I reset it every time? If so, it would seem most efficient to keep the code up top behind a '#' so I can just copy/paste every time I need it. I was hoping to just be able to call it every time, rather than rewrite it. But, this is not so bad either =) Thank you very much!!
Re: persistant random number generator, how to?
Posted: Fri Dec 21, 2018 5:08 pm
by Alex
You see $-sign means that there will be single-line python code.
Code: Select all
$ d20roll = renpy.random.randint(1,20)
is just the variable value asignment, it occures when this line executes. To re-assign value you need to run this line once again or make another similar line of code.
If you don't want to type this line again and again, you can create a function, like
Code: Select all
init python:
def my_roll(d=6):
return renpy.random.randint(1,d)
label start:
"..."
$ d6 = my_roll()
$ d20 = my_roll(20)
$ d100 = my_roll(100)
"d6 - [d6], d20 - [d20], d100 - [d100]"
"?"
jump start
Re: persistant random number generator, how to?
Posted: Sat Dec 22, 2018 12:05 am
by VorrAkkagi
Oh thanks!! This will help save a lot of time =)