using renpy.random for timing in an animated image / animation random time

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.
Post Reply
Message
Author
würstlbaron
Newbie
Posts: 3
Joined: Mon Oct 02, 2017 7:37 am
Contact:

using renpy.random for timing in an animated image / animation random time

#1 Post by würstlbaron »

hello!

i want to randomize the time between frames of an animated image, like this:

Code: Select all

image eileen blinking:
    "eileen open eyes.png"
    pause renpy.random.random()
    "eileen closed eyes.png"
    pause 0.2
    repeat
however, when i do this, it seems that the randomized pause time is only determined once, and that value is then always used when displaying the image. how can i achieve an effect where the time is randomized anew with each repetition of the animation?

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: using renpy.random for timing in an animated image / animation random time

#2 Post by Divona »

Perhaps something like this:

Code: Select all

default blink_timer = renpy.random.random()

init python:
    def blink(trans, st, at):
        global blink_timer

        if st >= blink_timer:
            blink_timer = renpy.random.random()
            return None
        else:
            return 0

image eileen blinking:
    "eileen open eyes.png"
    function blink
    "eileen closed eyes.png"
    pause 0.2
    repeat
See ATL Function Statement for more info.
Completed:
Image

würstlbaron
Newbie
Posts: 3
Joined: Mon Oct 02, 2017 7:37 am
Contact:

Re: using renpy.random for timing in an animated image / animation random time

#3 Post by würstlbaron »

Divona wrote: Mon Oct 02, 2017 8:54 am Perhaps something like this: [...]
perfect, works like a charm like that. thank you! :D

Post Reply

Who is online

Users browsing this forum: Google [Bot], Ocelot