Creating an 'active' clock?

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
goldenphoenyyx
Newbie
Posts: 12
Joined: Thu Jun 20, 2019 6:47 pm
Contact:

Creating an 'active' clock?

#1 Post by goldenphoenyyx »

Hello! I'm trying to figure out how to make an in-game clock that helps track the amount of days that have passed. I'm newer to coding, so I have a great lack of experience but want to keep learning. The way I'm currently trying to do it probably isn't the best way to go about it- maybe I'm thinking about this all wrong.

The clock that I currently have 'working' is a timer that I put into the screen file. As it counts down, the images change to whatever time of day it might be(morning, afternoon, night). The amount of seconds below is all testing, but I want to eventually make it longer if it works.

Code: Select all

screen countdown:
    timer 1 repeat True action If(time > 0, true=SetVariable('time', time - 1), false=[Hide('countdown'), Jump(timer_jump)])
    if time <= 2:
        text str(time) xpos .1 ypos .1 color "#FF0000" at alpha_dissolve
    else:
        text str(time) xpos .1 ypos .1 at alpha_dissolve

    if time <= 5:
        add "bg morning" xalign 1.0 yalign 0.5 at alpha_dissolve

    if time <= 3:
        add "bg afternoon" xalign 1.0 yalign 0.5 at alpha_dissolve

    if time <= 1:
        add "bg evening" xalign 1.0 yalign 0.5 at alpha_dissolve
With this here, I have another in the main script file that has a test for tracking the amount of days. That works fine, as the timer keeps resetting and adds to the variable. But it doesn't actually save the data outside of it, which I tested with the 'Checked Menu' option.

Code: Select all

    label timeKeeper:
        $ time = 5
        $ timer_range = 5
        $ timer_jump = 'timeKeeper'
        show screen countdown

        $ dayCount += 1

    label checkMenu:
        menu:
            "Check Days":
                "[dayCount]"
                jump checkMenu

                $ checkedMenu += 1

            "Do Nothing":
                "Mkay"
                jump checkMenu

            "Checked Menu":
                "[checkedMenu]"
                jump checkMenu

How can I keep it running in the background with resetting other dialogue/whatever I'm doing? Maybe I'm just going about this concept the wrong way? For more context, other things I'd want to use this clock for is events happening at certain times- for example, during the 'afternoon' an event can be triggered by being in the right area. Or a character having a birthday on a day in the season.

It certainly feels like there might be an easier way to code it and I'm just making it hard for myself. I would appreciate any help in this!

philat
Eileen-Class Veteran
Posts: 1910
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Creating an 'active' clock?

#2 Post by philat »

I would recommend looking at clock and calendar examples in the cookbook.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Creating an 'active' clock?

#3 Post by xavimat »

If I understand it correctly, you want a time counter running in the back independently of the actual story you are telling. It's doable, but I'd advise against it.The reason: every player has a different reading speed, your story will change according to that; I think it doesn't really make sense (IMHO).
I suggest you to have a simple variable to count the time, and integrate that variable inside your story (according to the choices the player does, the time goes on by a number of hours, for example; it depends on how long the protagonist takes to finish the selected option, not how long the reader takes to read the text).

Anyway, what you want can be done with a simple screen running on the background and triggering a function. No need to jump or hide it.

Code: Select all

default mytime = 0
default time_going = True
init python:
    def tempus_fugit():
        if time_going:
            global mytime 
            mytime += 1
screen time_goes():
    # change the number 60 according to your needs.
    timer 60 repeat True action Function(tempus_fugit)
    # Don't put more elements in this screen.
    # If you want to show the time, create another screen and show/hide it.
label start:
    show screen times_goes
    # time starts running.
    "What time is it?..."
    "[mytime]! Oh! So late!"
    # if you want to stop it for whatever reason:
    $ time_going = False
    # Turn in to True again to resume time-counting.
    # ....
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

goldenphoenyyx
Newbie
Posts: 12
Joined: Thu Jun 20, 2019 6:47 pm
Contact:

Re: Creating an 'active' clock?

#4 Post by goldenphoenyyx »

Thanks for the reply! This works well, thank you. And I totally get how people can read at different speeds, so I plan to pause the timer during main dialogue events so anyone can take as long or fast as the need. It's mostly just so I can make the world a little more dynamic with time of day and a night cycle. Thanks again for the help!

Post Reply

Who is online

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