I make a game, that has a lot of animated background and other arts. Because of that, I need a lot of random values. But I read some posts on this forum, and on another places, and it looks like that on renpy I can't use python random functions. It get me random value one time and on second time it get me same value. And only way to get a random value, is use renpy.random.choice( ... )
Is that right? Or maybe here is a way, and not only choice() can return random, int value? I read some posts, but because my English not so good, I think, maybe I miss something?
How to get random value in renpy
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.
- rururubell
- Newbie
- Posts: 13
- Joined: Mon Sep 30, 2019 4:00 am
- Deviantart: rururubell
- Contact:
How to get random value in renpy
Sorry for my English!
Re: How to get random value in renpy
Hi, rururubell,
Actually renpy.random.random(), renpy.random.randint(a,b) gives random numbers, but it also returns to the previous state with rollback and rollforward.
Actually renpy.random.random(), renpy.random.randint(a,b) gives random numbers, but it also returns to the previous state with rollback and rollforward.
- rururubell
- Newbie
- Posts: 13
- Joined: Mon Sep 30, 2019 4:00 am
- Deviantart: rururubell
- Contact:
Re: How to get random value in renpy
Hi, _ticlock_
I don't think it's problem if random() get same value after rollback and forward. But this atl code, for example doesn't work well.
If I use this code, "some_image" get some random position on screen but doesn't move. If I use this code:
"some_image" can move between random position, but it was randomized once. After all "some_image" will always move between two same positions. And I can get random positions, only if I use .choice()
I don't think it's problem if random() get same value after rollback and forward. But this atl code, for example doesn't work well.
Code: Select all
contains:
"some_image"
xpos renpy.random.randint( 0, 1920 )
ypos renpy.random.randint( 0, 1080 )
pause 1
repeat
Code: Select all
contains:
"some_image"
xpos renpy.random.randint( 0, 1920 )
ypos renpy.random.randint( 0, 1080 )
pause 1
xpos renpy.random.randint( 0, 1920 )
ypos renpy.random.randint( 0, 1080 )
pause 1
repeat
Sorry for my English!
Re: How to get random value in renpy
I think transform might not be very convenient for what you are trying to do. Consider DynamicDisplayable or CDD.
Anyway, for transform you can do something like this:
Anyway, for transform you can do something like this:
Code: Select all
init -1 python:
def t_func(trans,st,at):
if st > 1:
trans.xpos = renpy.random.randint( 0, 1280 )
trans.ypos = renpy.random.randint( 0, 720 )
return None
else:
return 0.05
image rand_pos:
"test.png"
block:
function t_func
pause 1.0
repeat
label start:
show rand_pos
"test.png changes its pos every 1 second"
Who is online
Users browsing this forum: No registered users