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
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

Timer

#1 Post by usul »

How do you start a timer to calculate the time it takes to complete a task?
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

User avatar
Alex
Lemma-Class Veteran
Posts: 3098
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Timer

#2 Post by Alex »

It`s something like this

Code: Select all

label start:

    scene black
    $ ui.timer(30.0, ui.jumps("too_slow"))
    $ ui.textbutton("Press me", clicked=ui.returns(True), xalign=.6, yalign=.3)
    $ ui.interact()
    "You did it...))"
    return

label too_slow:
    "... ..."
    return
http://www.renpy.org/wiki/ui.timer

User avatar
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

Re: Timer

#3 Post by usul »

yeah that part I get, I've seen it around the posts a lot these days, what I'm looking to do would be more like telling you how long it took.

something like:

timer start
user input
timer stop
it took you n seconds to respond
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

User avatar
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

Re: Timer

#4 Post by usul »

I found this on python.org, I think it might be of use in trying to figure out the time at the start and end of a task then calculating the difference. Not sure how I'll put it together yet, butI'll try to get it working tonight.

Code: Select all

>>> # dates are easily constructed and formatted
>>> from datetime import date
>>> now = date.today()
>>> now
datetime.date(2003, 12, 2)
>>> now.strftime("%m-%d-%y. %d %b %Y is a %A on the %d day of %B.")
'12-02-03. 02 Dec 2003 is a Tuesday on the 02 day of December.'

>>> # dates support calendar arithmetic
>>> birthday = date(1964, 7, 31)
>>> age = now - birthday
>>> age.days
14368
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Timer

#5 Post by PyTom »

I'd probably use the similar:

Code: Select all

init python:
    import time

$ start = time.time()

e "Go ahead, take your time."

$ time_taken = time.time() - start

e "You took %(time_taken)f seconds."
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

Timer

#6 Post by usul »

I get the following error:
TypeError: a float is required
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

User avatar
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

Re: Timer

#7 Post by usul »

I can't figure out how to make this code work, anyone got an idea?
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

chronoluminaire
Eileen-Class Veteran
Posts: 1153
Joined: Mon Jul 07, 2003 4:57 pm
Completed: Elven Relations, Cloud Fairy, When I Rule The World
Tumblr: alextfish
Skype: alextfish
Location: Cambridge, UK
Contact:

Re: Timer

#8 Post by chronoluminaire »

What code are you using precisely? Is it character-for-character copypasted from PyTom's post? And can you post the full error message and traceback?
I released 3 VNs, many moons ago: Elven Relations (IntRenAiMo 2007), When I Rule The World (NaNoRenO 2005), and Cloud Fairy (the Cute Light & Fluffy Project, 2009).
More recently I designed the board game Steam Works (published in 2015), available from a local gaming store near you!

User avatar
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

Re: Timer

#9 Post by usul »

My bad, it works just fine (I transcribed it from my cellphone when offline but having copy-pasted it today It works like a charm)

Thanks!!!
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

Post Reply

Who is online

Users browsing this forum: Bing [Bot]