How to make a timer?

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
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

How to make a timer?

#1 Post by isobellesophia »

Hello.

I would like to ask if there is some examples to make a timer code, it seems that i forgot how to do it or what site that i had visited ast month, and i want a timer in text/number will be displayed at top right.

Thanks.
I am a friendly user, please respect and have a good day.


Image

Image


rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: How to make a timer?

#2 Post by rayminator »

here are some here for you to look at

viewtopic.php?t=13381
viewtopic.php?f=8&t=42301&p=442246

and there is more here
viewtopic.php?f=51&t=34131

just play around and revers it somehow to change it a timer or do want a countdown timer

verysunshine
Veteran
Posts: 339
Joined: Wed Sep 24, 2014 5:03 pm
Organization: Wild Rose Interactive
Contact:

Re: How to make a timer?

#3 Post by verysunshine »

There is a timer in Screen Language now. The only issue is that it doesn't have any visuals by default. It's not clear what the variables for the timer are, so I went splunking through the code. Unfortunately, even after going through screen_language, ui, game, and behavior, I can't find where the timer decrementing is handled. My guess is that the variable is in TimerState() or Timer(), which I can't locate at the moment.

Either way, the code to put a timer on the screen should be:

Code: Select all

screen showtimer():
    vbox:
        spacing 15
        timer 3.0 action Jump("too_slow")
        text "TIME REMAINING: %d SECONDS" % (whatever_the_variable_is)
I just need to find the name of that variable.

Edit: Solved in another thread. False alarm. That's for a timer where the delay is shown.

Build the basics first, then add all the fun bits.

Please check out my games on my itch.io page!

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: How to make a timer?

#4 Post by hell_oh_world »

Code: Select all

screen my_timer(timeout):
  default time = timeout
  if time != 0:
    timer 1.0 repeat True action SetScreenVariable("time", time - 1)
  # else:
  #  timer 0.01 action Hide("my_timer") # add these two lines of code if you want the timer to disappear automatically.
  text str(time) align (0.5, 0.5)

label start:
  show screen my_timer(5.0)
  "some dialogue"
  hide screen my_timer

verysunshine
Veteran
Posts: 339
Joined: Wed Sep 24, 2014 5:03 pm
Organization: Wild Rose Interactive
Contact:

Re: How to make a timer?

#5 Post by verysunshine »

Thank you, hell_oh_world!

Build the basics first, then add all the fun bits.

Please check out my games on my itch.io page!

Post Reply

Who is online

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