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 everyone! Back at it again with another randint question. I have a 1-12 outcome, with potential buff (or subtraction) that could potentially pull the result up to 13. I'd like that to be scaled back down to a 12 and I thought the following would help, but instead it just sets it permanently to 12 and I just don't see why.
firs thing first, no need for [] to read a variable in an if clause (might actually be the cause of your problem). Other than that, I haven't seen a good way yet. I one created a python container with the add and remove function to render the calulation automatic. It might be a good choice in your case:
init python in vim:
vim = 0
def set(val):
global vim
vim = val
def get():
return vim
def roll():
global vim
val = renpy.random.randint(1,12) +vim
if val > 12:
val = 12
return val
Then in you game you should be able to get a direct value with vim.roll()
Edit: if you have a lot of characteristic that act like this, you migth want to create a class instead. You could also do the same, but for the different dice instead.
Chances are, it's because of the brackets. I do this with variables for my game all the time, and it works perfectly well for me.
Change [vimroll] to vimroll, and it should be fine.
~There is almost always a better, easier way to approach a problem.~
@lacticacid, @nature1996: you were both completely right, it was my brackets that messed things up! I should've seen it, but now it's clearer, so thank you both.
@Remix: doing it this way is much smoother; the less computational time the better. Would you mind explaining what's actually going on in the equation? Why does "min" cap things when, you'd think, "max" would be the operative word? Unless that's not what min stands for at all XD
philat wrote: ↑Tue May 14, 2019 9:09 pm
It means take the smaller of 12 and the result of the random roll. max() does the opposite (take the larger number).
Ahh, okay! Thank you for taking the time to explain; I really appreciate it!