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...
persistant random number generator, how to?
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.
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.
-
- Newbie
- Posts: 22
- Joined: Tue Dec 11, 2018 5:41 am
- Contact:
Re: persistant random number generator, how to?
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]
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
-
- Newbie
- Posts: 22
- Joined: Tue Dec 11, 2018 5:41 am
- Contact:
Re: persistant random number generator, how to?
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!!
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?
You see $-sign means that there will be single-line python code.
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
$ d20roll = renpy.random.randint(1,20)
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
-
- Newbie
- Posts: 22
- Joined: Tue Dec 11, 2018 5:41 am
- Contact:
Re: persistant random number generator, how to?
Oh thanks!! This will help save a lot of time =)
Who is online
Users browsing this forum: 3N16M4, Google [Bot]