Renpy Timer Question(s)

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
User avatar
Hentai Poofter
Posts: 2117
Joined: Sat Feb 04, 2006 11:13 pm
Organization: Studio Mugenjohncel
Location: Philippines

Renpy Timer Question(s)

#1 Post by mugenjohncel » Sat Jan 07, 2012 6:17 pm

I'll go to the point...How do I...

▪ Show a Timer that is similar to the one on the Ren'py tutorial?
▪ How do I make it 99 seconds instead of 10?
▪ Make it jump to a label by force once it reaches 00.00?
▪ Dictate the font and the size?
▪ Dictate the position in pixels?
In case you're reading this Alex... this is very much related to that electrified thingy you sent me quite a while ago... and I'm putting it to good use... I'll credit you of course...
"POOF" (Disappears)

Posts: 299
Joined: Thu Jul 07, 2011 9:33 am
Projects: BloomingBlossoms

Re: Renpy Timer Question(s)

#2 Post by tuna_sushi » Sat Jan 07, 2012 8:59 pm

I can only answer #1,2,3

to show the timer:

Code: Select all


        # This function will run a countdown of the given length. It will
        # be white until 5 seconds are left, and then red until 0 seconds are
        # left, and then will blink 0.0 when time is up. 
        def countdown(st, at, length=0.0):

            remaining = length - st

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

    # Show a countdown for 10 seconds.
    image countdown = DynamicDisplayable(countdown, length=5.0)
...somewhere else...

Code: Select all

show countdown at Position(xalign=.1, yalign=.1)

to change the length:

Code: Select all

image countdown = DynamicDisplayable(countdown, length=5.0)

Code: Select all


Code: Select all


to jump to a label if it ends:

Code: Select all

show countdown at Position(xalign=.1, yalign=.1)
$ ui.timer(5.0, ui.jumps("slow"))
            jump yes
            jump no
label slow:
    hide countdown
    "You're too slow."
label yes:
    hide countdown

label no:
    hide countdown
hope it helps!

Posts: 7
Joined: Sat Jun 13, 2020 4:48 am

Re: Renpy Timer Question(s)

#3 Post by mahin101 » Tue Sep 01, 2020 1:48 am

How do I restart the timer as soon as it hits 0 ?

User avatar
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines

Re: Renpy Timer Question(s)

#4 Post by hell_oh_world » Tue Sep 01, 2020 3:08 am

restarting a timer is pretty easy just some conditionals...

Code: Select all

screen timer(duration=5):
  default time = duration
  timer 1.0:
    repeat True
    action [
      SetScreenVariable("time", time - 1),
      If(time == 0, SetScreenVariable("time", duration))

  text str(time) align (0.5, 0.5)

label start:
  show screen timer(10)

Post Reply

Who is online

Users browsing this forum: Bing [Bot]