Timer inside 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
AoiUsui
Regular
Posts: 42
Joined: Mon Nov 26, 2012 11:21 am
Completed: Alice's Dolls
Projects: Alice's Dolls, Tappy Virus
Organization: Otaku Brigade
itch: otakubrigade
Location: Philippines
Contact:

Timer inside a timer

#1 Post by AoiUsui » Wed Dec 12, 2012 6:18 am

We have a problem about timer, we used the sample codes found on the tutorial. After the countdown finishes, we need to time the blinking text (caption) for a minute then the countdown starts again from the start. It is actually a repetitive process. How can we made it like that?

We are beginners in Ren'Py.

Please, help us! Thanks in advance! :)

User avatar
PyTom
Ren'Py Creator
Posts: 15663
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 inside a timer

#2 Post by PyTom » Wed Dec 12, 2012 10:59 pm

Probably the easiest way is to use the module operator on st:

Code: Select all

st = st % 60
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
AoiUsui
Regular
Posts: 42
Joined: Mon Nov 26, 2012 11:21 am
Completed: Alice's Dolls
Projects: Alice's Dolls, Tappy Virus
Organization: Otaku Brigade
itch: otakubrigade
Location: Philippines
Contact:

Re: Timer inside a timer

#3 Post by AoiUsui » Fri Dec 14, 2012 1:27 am

Where can we insert that code? And does it make it repetitive?

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 > 5.0:
return Text("%.1f" % remaining, color="#fff", size=25), .1
elif remaining > 0.0:
return Text("%.1f" % remaining, color="#f00", size=25), .1
else:
return anim.Blink(Text("Reminder: You are playing for more than 2 hours.", size=40 , color="#FF9900")), None

image countdown = DynamicDisplayable(countdown, length=5.0)


Thank you! :)

Levrex
Veteran
Posts: 280
Joined: Mon Jun 18, 2012 12:16 pm
Contact:

Re: Timer inside a timer

#4 Post by Levrex » Fri Dec 14, 2012 4:08 pm

Have fun.

Code: Select all

init:
    python:
        def countdown(st, at, length=0.0):
            copied_st = st % (length + 60) # Had to copy "st", because "st" is NoneType and can't be operated with directly.
            remaining = length - copied_st
    
            while remaining >= 0:
                return Text("%.1f" % remaining, color="#fff", size=25), .1
            while remaining >= -60:
                return anim.Blink(Text("0.0", color="#f00", size=64)), None

    # Show a countdown for 10 seconds.
    image countdown = DynamicDisplayable(countdown, length=15)
If your question is solved, please add [Solved] to theme's name by editing its first post, so that the helpful guys out there wouldn't mistakenly think the problem is still unanswered and waste their time.

User avatar
AoiUsui
Regular
Posts: 42
Joined: Mon Nov 26, 2012 11:21 am
Completed: Alice's Dolls
Projects: Alice's Dolls, Tappy Virus
Organization: Otaku Brigade
itch: otakubrigade
Location: Philippines
Contact:

Re: Timer inside a timer

#5 Post by AoiUsui » Sat Dec 15, 2012 6:48 am

I will try this! :D Thank you very much!

It solved our problem! Thank you very much! :)

User avatar
AoiUsui
Regular
Posts: 42
Joined: Mon Nov 26, 2012 11:21 am
Completed: Alice's Dolls
Projects: Alice's Dolls, Tappy Virus
Organization: Otaku Brigade
itch: otakubrigade
Location: Philippines
Contact:

Re: Timer inside a timer

#6 Post by AoiUsui » Thu Feb 23, 2017 5:04 am

Its been a while since I first post this. But there is a version 2 of the game we are previously working at.

With this codes, how can we make the player to choose countdown time? For example: 30 minutes, 1 hour or 2 hours.

I hope that you can help me again.

Thanks.

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

Re: Timer inside a timer

#7 Post by Alex » Thu Feb 23, 2017 6:25 am

Have you seen this thread - viewtopic.php?f=8&t=7337&hilit=countdown?

User avatar
AoiUsui
Regular
Posts: 42
Joined: Mon Nov 26, 2012 11:21 am
Completed: Alice's Dolls
Projects: Alice's Dolls, Tappy Virus
Organization: Otaku Brigade
itch: otakubrigade
Location: Philippines
Contact:

Re: Timer inside a timer

#8 Post by AoiUsui » Tue Feb 28, 2017 3:27 am

Thank you for the reply and for the link. I'm trying to incorporate it first in an experiment and I'm having an issue. I attach here the screenshot.

I hope that you can still help me in this. Thanks again.
Attachments
Ren'py issue.PNG
Screenshot of the issue encountered.

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: Timer inside a timer

#9 Post by Divona » Tue Feb 28, 2017 3:49 am

You have "def countdown()" and "image countdown". I would try to avoid duplication name.

Also on line 9, instead of

Code: Select all

python:
Try:

Code: Select all

init python:
Completed:
Image

User avatar
AoiUsui
Regular
Posts: 42
Joined: Mon Nov 26, 2012 11:21 am
Completed: Alice's Dolls
Projects: Alice's Dolls, Tappy Virus
Organization: Otaku Brigade
itch: otakubrigade
Location: Philippines
Contact:

Re: Timer inside a timer

#10 Post by AoiUsui » Wed Mar 01, 2017 5:30 am

It seems that it solved the problem, but I still encountered an issue. It has no error messages but it doesn't work.

I'm sorry, I'm not a much into programming. But please help me. Thanks also.

Code: Select all

label start:

    e "Please choose countdown."
    menu:
        "10 Seconds":
            jump sec10
        "30 Seconds":
            jump sec30
        "60 Seconds":
            jump sec60
    
    label sec10:
        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 = 10.0

                if hasattr(store, 'bulles_temps'):
                    length = store.bulles_temps

                remaining = length - st
   
                if remaining > 5.0:
                    return Text("%.1f" % remaining, color="#fff", size=64), .1
                elif remaining > 0.0:
                    return Text("%.1f" % remaining, color="#f00", size=64), .1
                else:
            #return anim.Blink(Text("0.0", color="#f00", size=64)), None
                    renpy.jump('end')

    # Show a countdown for 10 seconds.
    #image countdown = DynamicDisplayable(countdown)

    e"You selected 10 seconds, please wait for 10 seconds."
    return

Post Reply

Who is online

Users browsing this forum: Google [Bot]