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

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)

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

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

init:
    python:

        # 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
            else:
                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)
change

Code: Select all

length=5.0
to

Code: Select all

length=99.0


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"))
menu:
        "Yes":
            jump yes
        "No":
            jump no
   
label slow:
    hide countdown
    "You're too slow."
    
label yes:
    hide countdown
    "..."

label no:
    hide countdown
    "..."
hope it helps!

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

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
hell_oh_world
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
Contact:

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)
  "Countdown!"

Post Reply

Who is online

Users browsing this forum: Bing [Bot]