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.
-
Steffenator
- Regular
- Posts: 53
- Joined: Fri Feb 17, 2017 11:58 am
-
Contact:
#1
Post
by Steffenator » Tue Dec 31, 2019 4:07 pm
Gentlemen,
I'm trying to animate my side images, but have a random pause duration between cycles.
What I've tried is to tell the last image in the list to pause for a random period between 2, and 7 seconds using the renpy random interger thingy.
I employed it two ways with the same result. One by adding it directly to the pause duration of the last frame, the other by setting up a variable to be used as the pause duration. (Below)
Direct version:
Code: Select all
"images/Animations/MeredithSideImage-001_0025.png"
pause renpy.random.randint(2, 7)
repeat
Variable Version:
Variable:
Code: Select all
$ rInt = renpy.random.randint(2, 7)
Applied in frame:
Code: Select all
"images/Animations/MeredithSideImage-001_0025.png"
pause rInt
repeat
They both allow the script to function, but instead of giving me a random pause duration, it seems to split the difference, and give me a 5 second pause between each cycle.
What did I break?
There once was a language called Ren'Py
that made all the wannabes cry... with joy.
It gave them the power,
they spent every hour,
to finish a game, or die.

-
Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
-
Contact:
#2
Post
by Remix » Tue Dec 31, 2019 4:50 pm
A transform (or ATL within an image declaration) is evaluated at init time. By that, I mean the random part is calculated once and then set in stone.
Short of using some form of dynamic displayable or blocking function call in the ATL (which might be tricky), you could get around it by using the choice keyword:
Code: Select all
image whatever:
"images/Animations/MeredithSideImage-001_0025.png"
choice:
2.0
choice:
3.0
choice:
4.0
choice:
5.0
choice:
6.0
choice:
7.0
repeat
-
Steffenator
- Regular
- Posts: 53
- Joined: Fri Feb 17, 2017 11:58 am
-
Contact:
#3
Post
by Steffenator » Tue Dec 31, 2019 5:58 pm
Cool, that totally worked... How would one put that into a variable?
I like to put stuff like that into variables, since I'll be making a bunch of animated side-images.

There once was a language called Ren'Py
that made all the wannabes cry... with joy.
It gave them the power,
they spent every hour,
to finish a game, or die.

-
Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
-
Contact:
#4
Post
by Remix » Wed Jan 01, 2020 12:03 pm
The only real way I've found to do that is to use a 'blocker/pauser' function that only allows progress after a random delay.
For multiple sprites all wanting their own randomness it does though mean giving each a unique id
Code: Select all
init python:
import time
pause_state = {}
def random_pause(trans, st, at, id="unique", pause_range=(1.0, 5.0)):
"""
Create a random value between the supplied floats and only
return None after that delay has passed. Effectively pausing
the ATL for that duration
"""
global pause_state
recheck = 0.05
cur_time = time.time()
if (not id in pause_state
or pause_state[ id ] < (cur_time - (2.0*recheck))):
# new or expired, so create or refresh the delay time
rnd = renpy.python.random.uniform(*pause_range)
pause_state[ id ] = cur_time + rnd
return None if pause_state[ id ] < cur_time else recheck
image small_pic:
"images/maid.jpg"
rotate 0.0
anchor (0.5, 0.5)
rotate_pad True
linear 1.5 rotate 360.0
function renpy.curry(random_pause)(id="maid", pause_range=(0.5, 7.4))
repeat
Each would need just the
function renpy.curry(random_pause)(id="maid", pause_range=(0.5, 7.4)) part where they wanted to pause
-
strayerror
- Regular
- Posts: 154
- Joined: Fri Jan 04, 2019 3:44 pm
-
Contact:
#5
Post
by strayerror » Wed Jan 01, 2020 12:13 pm
Another option, extending Remix's original suggestion (and only useful if the limits on your random int don't change between images) could be to use a parameterised transform. It comes down to how much flexibility vs complexity you need and what you're comfortable maintaining. :)
Code: Select all
image anim: # sample animation of three frames just for this example
Solid('f00', xysize=(100, 100))
pause .5
Solid('0f0', xysize=(100, 100))
pause .5
Solid('00f', xysize=(100, 100))
transform wait(i): # parameterised version of Remix's transform
i
choice:
2.0
choice:
3.0
choice:
4.0
choice:
5.0
choice:
6.0
choice:
7.0
repeat
label start:
scene
show expression wait('anim') as anim # applying wait transform to animation
'Example'
return
Users browsing this forum: Bing [Bot], Google [Bot]