Timer using persistent data [HELP]

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
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

Timer using persistent data [HELP]

#1 Post by beastcarving »

I thought it would be cool to unlock a scene after a real 60 minutes has passed.
I'd like you to still be able to play the rest of the game though while the time counts down in the background and even when the game is closed.
After 60 mins go by, the scene should be unlocked. Kinda like those texting simulator games. Is there a way to do this?

Here's what I've got so far:
This is a basic timer in which it restarts after clicking on a menu. I'd like a timer that doesn't restart every time I open a menu or even close the game. I'd like to have the timer running in the background until it's at zero and the reward is unlocked. I'd like the timer to restart after the old reward is claimed, and then you can then wait for the next reward in line to countdown.

Code: Select all

init:
    python:

        def countdown(st, at, length=0.0):

            persistent.remaining = length - st
            minutes = (int) (length - st) / 60
            seconds = (int) (length - st) % 60


            if persistent.remaining > 10.0:
                return Text("%02d:" % minutes + "%02d" % seconds, color="#fff", size=48), .1
            elif persistent.remaining > 0.0:
                return Text("%02d:" % minutes + "%02d" % seconds, color="#f00", size=48), .1
            else:
                renpy.jump("reward")

label reward:
    "Bob's back from the war."
    bob"Thanks for waiting."
    return
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

prestristan
Regular
Posts: 25
Joined: Sat Apr 11, 2020 1:28 pm
Contact:

Re: Timer using persistent data [HELP]

#2 Post by prestristan »

This might be the one you're looking for?
viewtopic.php?t=48299#p478576

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Timer using persistent data [HELP]

#3 Post by gas »

Try this...

Code: Select all

### Unlock stuff after a while!

init python:
    if not persistent.runtime:
        persistent.runtime = 0
    if persistent.collected_awards == None:
        persistent.time_awards = ["awards1", "awards2"]
	persistent.collected_awards = []

    def calc_total_run():
        persistent.runtime += renpy.get_game_runtime()
        renpy.clear_game_runtime()
    config.python_callbacks.append(calc_total_run)
	
    def unlock_time_awards():
        if persistent.time_awards and persistent.runtime == 300: #(300 = 5 minutes)
            persistent.runtime = 0
	    persistent.collected_awards.append(persistent.time_awards.pop(0))
    config.python_callbacks.append(unlock_time_awards)

label start:
    e "Stay put..."
    e "Your collected time awards so far are: [persistent.collected_awards]"
    e "Bye, be back later"
    return
This code *should* automaticly move each 5 minutes (300) one award from the list of awards (persistent.time_awards) to the list of collected awards (persistent.collected_awards).
If you need more complex triggering (like different time triggers - after 5 mintes, after one hour, after 3 days) just ask, but first do some testing, I can't do it right now.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

Re: Timer using persistent data [HELP]

#4 Post by beastcarving »

Instead of a list, I'd like the reward to be accepted through a label. For example:

Code: Select all

if bob route == "dating bob":
	## Timer stuff... timer at 0:00
	jump reward1

label reward1:
     $ persistent.reward +=1
     return
This way I can know when to unlock certain scenes judging by how much time has gone by using reward points.
Ex. If you have 1 point "Bob's back from the war."
If two points "Bob's birthday."

I'd like to see the timer counting down an hour until the reward is collected at 0:00. I'd like to also place this countdown timer on the Main Menu so you can see how much time is left.

When the game closes somehow I'd like the hour to still countdown, and when you reopen the game the timer is closer to finishing. I'd like it if nothing can interrupt the timer or reset it when it starts.
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

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: Timer using persistent data [HELP]

#5 Post by trooper6 »

I think you are taking the wrong approach. You don't actually need a timer going like that. You just need to import python's date time module, Put the starting date time in a persistent variable when the player starts the game and then whenever the game is up, check the real time against that original time date.

But here is my question. Let's say I download your game. I start it up for about five minutes, but then I have to quit the game to work on homework or whatever. Then I come back to your game one month later. The game is probably going to be in some super strange state and I'll have no idea what's going on. I'm not sure that would be fun for the player.
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

User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

Re: Timer using persistent data [HELP]

#6 Post by beastcarving »

Let's say I download your game. I start it up for about five minutes, but then I have to quit the game to work on homework or whatever. Then I come back to your game one month later. The game is probably going to be in some super strange state
I'm using points so I can make a way to show only two rewards at a time. I f you have less than two rewards the timer will start again, counting down your next reward. As soon as you gain two reward points that you didn't spend yet. The timer will stop until you spend both or one reward point.
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

Re: Timer using persistent data [HELP]

#7 Post by beastcarving »

I really need help making it though.
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

prestristan
Regular
Posts: 25
Joined: Sat Apr 11, 2020 1:28 pm
Contact:

Re: Timer using persistent data [HELP]

#8 Post by prestristan »

Try this code sent by

Per K Grok on my post similar to this: viewtopic.php?f=8&t=58606&p=527578#p527578

Code: Select all

default timeleft=10
default point=0

screen cash():
    if timeleft>1:
        timer 1.0 action SetVariable("timeleft", timeleft-1) repeat True
    elif timeleft==1:
        timer 1.0 action [SetVariable("timeleft", 0), SetVariable("point", point+1) ]
    elif timeleft==0:
        timer 1.0 action SetVariable("timeleft", 10)
    vbox:
        text "Eileen's Points: [point]"
        if timeleft>0:
            text "+1 in [timeleft] seconds"
To be honest I also wanna know how to make this feature work.
I posted a month ago and I cant seem to get how to make it work.
Hopefully someone knows

User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

Re: Timer using persistent data [HELP]

#9 Post by beastcarving »

To be honest I also wanna know how to make this feature work.
I posted a month ago and I cant seem to get how to make it work.
Hopefully someone knows
I went ahead and moved to that form to see if we can get more answers.
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

Post Reply

Who is online

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