Page 1 of 1

Text-based timer?

Posted: Thu Jul 21, 2016 5:58 am
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...

Re: Text-based timer?

Posted: Thu Jul 21, 2016 7:08 am
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

Re: Text-based timer?

Posted: Thu Jul 21, 2016 7:56 am
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...

Re: Text-based timer?

Posted: Thu Jul 21, 2016 11:03 am
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.

Re: Text-based timer?

Posted: Thu Jul 21, 2016 11:16 am
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

Re: Text-based timer?

Posted: Thu Jul 21, 2016 11:49 am
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.