I noticed that if I import random in an init python block I can use
random.randint() everywhere in the code, instead of renpy.random.randint() which I think didn't work in python blocks anyway.
Is there some specific reason why we don't do this by default? Wouldn't it be shorter and less confusing this way.
Is this a thing which was not possible in earlier versions of renpy?
random.randint() and renpy.random.randint()
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.
-
- Eileen-Class Veteran
- Posts: 1258
- Joined: Fri Sep 21, 2007 7:13 am
- Projects: a battle engine
- Contact:
Re: random.randint() and renpy.random.randint()
renpy.random works in python blocks, just not init blocks.
renpy.random is the same as random, except it plays nicely with rollback- i.e. if you do something like this:
$roll = random.randint(1, 6)
"You rolled a [roll]!"
and you rollback or save/load, the number rolled could be different. Using renpy.random avoids this, ensuring the same numbers are generated each time (plus you don't need the import) This is highly useful for e.g. games with random events or stats, ensuring that you can't just bypass by wiggling your mousewheel (although I'd probably go insane in Magical Diary if I couldn't do this, so... =P)
Naturally, in an init block there is no need for rollback so go ahead and use random without worrying about it.
renpy.random is the same as random, except it plays nicely with rollback- i.e. if you do something like this:
$roll = random.randint(1, 6)
"You rolled a [roll]!"
and you rollback or save/load, the number rolled could be different. Using renpy.random avoids this, ensuring the same numbers are generated each time (plus you don't need the import) This is highly useful for e.g. games with random events or stats, ensuring that you can't just bypass by wiggling your mousewheel (although I'd probably go insane in Magical Diary if I couldn't do this, so... =P)
Naturally, in an init block there is no need for rollback so go ahead and use random without worrying about it.
Last edited by Asceai on Thu Feb 27, 2014 4:14 am, edited 1 time in total.
Re: random.randint() and renpy.random.randint()
So it's for rollback, thanks, that answers my question perfectlyAsceai wrote:renpy.random works in python blocks, just not init blocks.
renpy.random is the same as random, except it plays nicely with rollback- i.e. if you do something like this:
$roll = random.randint(1, 6)
"You rolled a [roll]!"
and you rollback or save/load, the number rolled could be different. Using renpy.random avoids this, ensuring the same numbers are generated each time (plus you don't need the import)
Naturally, in an init block there is no need for rollback so go ahead and use random without worrying about it.
- Rosstin2
- Veteran
- Posts: 253
- Joined: Thu Jan 09, 2014 12:42 pm
- Completed: King's Ascent, Kitty Love
- Projects: Queen At Arms, Rex Rocket
- Organization: Aqualuft Games
- Contact:
Re: random.randint() and renpy.random.randint()
Interesting, this is some insight into why I couldn't use Renpy.Random in my init blocks earlier.
Who is online
Users browsing this forum: No registered users