Page 1 of 1

Renpy Timer Question(s)

Posted: Sat Jan 07, 2012 6:17 pm
by mugenjohncel
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)

Re: Renpy Timer Question(s)

Posted: Sat Jan 07, 2012 8:59 pm
by tuna_sushi
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!

Re: Renpy Timer Question(s)

Posted: Tue Sep 01, 2020 1:48 am
by mahin101
How do I restart the timer as soon as it hits 0 ?

Re: Renpy Timer Question(s)

Posted: Tue Sep 01, 2020 3:08 am
by hell_oh_world
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!"