Text-based 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
UselessCoder
Regular
Posts: 96
Joined: Sun Jan 24, 2016 6:51 am
Projects: undisclosed...
Contact:

Text-based timer?

#1 Post by UselessCoder »

Hi,
just a "conceptual" question out of my attempts to get my project more functional and less heavy in terms of assets:

...Is there a way to code a displayable as if it was a timer?

As of now, I've achieved this by creating an animation where every single frame is a number (from 0 to 100= 100 pngs = mental!) and it works, but at the price of a moderate loss in terms of disk space (not to mention health loss in the process on my side, lol).

Once again, thanks to anyone who would share his/her knowledge on the matter...

User avatar
andrewngn13
Regular
Posts: 65
Joined: Thu Nov 13, 2014 2:41 pm
Projects: Recast
Skype: andrewngn13
Location: Glued to my desktop
Contact:

Re: Text-based timer?

#2 Post by andrewngn13 »

I'm not sure I understand the question's context...but you want to create a timer displayable is what I'm getting.

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)
and elsewhere

Code: Select all

show countdown at Position(xalign=.1, yalign=.1)
source: viewtopic.php?f=8&t=13381
"Feel feel to idea-bounce off me."
No, like seriously, just send a pm and I'll respond what I think. I'm open to reading anything.

UselessCoder
Regular
Posts: 96
Joined: Sun Jan 24, 2016 6:51 am
Projects: undisclosed...
Contact:

Re: Text-based timer?

#3 Post by UselessCoder »

hi andrewngn13 and thanks for your answer.
Unfortunately that example is not what I was looking for...I'm looking for a counter like from "0" to "10" but I need that numbers to be text and not images (like the one I've created).

Maybe I could create some "image" made of text like:

image counter:
text ("0")
pause 1
text ("1")

and so on...I don't know, I'm just guessing...

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Text-based timer?

#4 Post by trooper6 »

Go to the Tutorial game (which you can access from the Renpy Launcher) and check out DynamicDisplayables. That will give you want you want.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

UselessCoder
Regular
Posts: 96
Joined: Sun Jan 24, 2016 6:51 am
Projects: undisclosed...
Contact:

Re: Text-based timer?

#5 Post by UselessCoder »

trooper6 wrote:Go to the Tutorial game (which you can access from the Renpy Launcher) and check out DynamicDisplayables. That will give you want you want.
Pretty much what andrew posted above. Thanks anyway

User avatar
andrewngn13
Regular
Posts: 65
Joined: Thu Nov 13, 2014 2:41 pm
Projects: Recast
Skype: andrewngn13
Location: Glued to my desktop
Contact:

Re: Text-based timer?

#6 Post by andrewngn13 »

Code: Select all

init:
    python:

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

            remaining = length + st

            if remaining == 0.0:
                return anim.Blink(Text("0.0", color="#f00", size=72)), None
            elif remaining > 5.0 and remaining < 10.0:
                return Text("%1.0f" % remaining, color="#fff", size=72), 1.0
            elif remaining > 0.0 and remaining < 10.0:
                return Text("%1.0f" % remaining, color="#f00", size=72), 1.0
            else:
                return anim.Blink(Text("10.0", color="#f00", size=72)), None

    # Show a countup for 10 seconds.
    image countdown = DynamicDisplayable(countdown, length=0.0)
Sidestepping around python errors because I honestly don't really know python. This counts up from 0 to 10 and ends up blinking 10.0 at the end. I'm not too much what you mean by numbers being text not images because these are quite literally text characters being shown on screen.
"Feel feel to idea-bounce off me."
No, like seriously, just send a pm and I'll respond what I think. I'm open to reading anything.

Post Reply

Who is online

Users browsing this forum: VESTED