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.
Hi, so I'm trying to use renpy.random to generate some random lines of dialogue, or for nothing to happen, whenever a certain button is pressed. The code I have works, but only once- the next time the button is pressed, it uses the same option as what was chosen before. How can I use renpy random to generate more than one outcome?
each time you need a random number.
So, you need to show more code: how did you make your certain button and where in the game flow you need to get this random dialogs.
each time you need a random number.
So, you need to show more code: how did you make your certain button and where in the game flow you need to get this random dialogs.
so the code is under a label that's called every time a button is pressed. The $randomconvo variable is assigned right under the label, so I assumed it would be rerun each time the jump to that label was made, but it hasn't worked that way.
screen bttn_scr():
textbutton "Press Me" action Jump("my_label") align (0.5,0.05)
label my_label:
$ var = renpy.random.randint(1,3)
if var == 1:
"...[var]..."
elif var == 2:
"___[var]___"
else:
"~~~[var]~~~"
jump start
label start:
scene black
show screen bttn_scr
"..."
"?"
screen bttn_scr():
textbutton "Press Me" action Jump("my_label") align (0.5,0.05)
label my_label:
$ var = renpy.random.randint(1,3)
if var == 1:
"...[var]..."
elif var == 2:
"___[var]___"
else:
"~~~[var]~~~"
jump start
label start:
scene black
show screen bttn_scr
"..."
"?"
After testing it some more times, I found it was working properly! I think the issue was I was trying to get it to make a new integer just by using rollback rather than leaving the scenario and coming back again like players would actually do in the game. Thank you!