Real Time Clock While Waiting User

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
vdp
Newbie
Posts: 3
Joined: Sun May 03, 2009 1:22 pm
Contact:

Real Time Clock While Waiting User

#1 Post by vdp »

I want to make a countdown / timer, but I haven't found any way how to update it in real time (while waiting user typing / clicking / other type of transaction). After asking around renpy channel in IRC and searching through old threads, I found out that I can do it with combination of screen timer and DynamicDisplayable. Try this sample below:

Code: Select all

define boss = Character('Boss', color="#ffc8ff")

screen hidden_timer:
    timer 5.0 action ui.jumps("boss_said_slow")

init:
    python:
        def countdown(st, at, length=0.0):

            remaining = length - st

            if remaining > 5.0:
                return Text("%.1f" % remaining, color="#fff", size=72), .1
            elif remaining > 0.0:
                return Text("%.1f" % remaining, color="#f00", size=72), .1
            else:
                return anim.Blink(Text("0.0", color="#f00", size=72)), None

    image countdown = DynamicDisplayable(countdown, length=5.0)

# The game starts here.
label start:
    boss "Bomb will explode in 5.0... except you enter the password!"
    call show_timer
    $ password = ''
    while (password != "password"):
        $ password = renpy.input("Let's see. The password is...")
    call hide_timer
    boss "Good! you defuse it!"
    return

label boss_said_slow:
    if (run_timer == True):
        call hide_timer
        boss "BOMB! you are to slow!"
        ".: Game Over :."
    return

label hide_timer:
    $ run_timer = False
    hide screen hidden_timer
    hide countdown
    with dissolve
    return

label show_timer:
    $ run_timer = True
    show screen hidden_timer
    show countdown at Position(xalign=.1, yalign=.1)
    return

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]