{Solved} Clock loop isn't working, anyone know why?

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
Verstehen
Newbie
Posts: 10
Joined: Sun Sep 15, 2013 5:40 pm
Contact:

{Solved} Clock loop isn't working, anyone know why?

#1 Post by Verstehen » Sun Sep 15, 2013 5:52 pm

I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/Local1.rpy", line 552, in script (<- This was the script that was calling for the stat to be shown.)
File "game/Stats.rpy", line 795, in python
KeyError: 'clock'

Code: Select all

    if minutes > 1380:
        $ minutes = 0
    elif minutes == 0:
        $ clock = "12:00 AM"
    elif minutes == 60:
        $ clock = "1:00 AM"
    elif minutes == 120:
        $ clock = "2:00 AM"
    elif minutes == 180:
        $ clock = "3:00 AM"
    elif minutes == 240:
        $ clock = "4:00 AM"
    elif minutes == 300:
        $ clock = "5:00 AM"
    elif minutes == 360:
        $ clock = "6:00 AM"
    elif minutes == 420:
        $ clock = "7:00 AM"
    elif minutes == 480:
        $ clock = "8:00 AM"
    elif minutes == 540:
        $ clock = "9:00 AM"
    elif minutes == 600:
        $ clock = "10:00 AM"
    elif minutes == 660:
        $ clock = "11:00 AM"
    elif minutes == 720:
        $ clock = "12:00 PM"
    elif minutes == 780:
        $ clock = "1:00 PM"
    elif minutes == 840:
        $ clock = "2:00 PM"
    elif minutes == 900:
        $ clock = "3:00 PM"
    elif minutes == 960:
        $ clock = "4:00 PM"
    elif minutes == 1020:
        $ clock = "5:00 PM"
    elif minutes == 1080:
        $ clock = "6:00 PM"
    elif minutes == 1140:
        $ clock = "7:00 PM"
    elif minutes == 1200:
        $ clock = "8:00 PM"
    elif minutes == 1260:
        $ clock = "9:00 PM"
    elif minutes == 1320:
        $ clock = "10:00 PM"
    elif minutes == 1380:
        $ clock = "11:00 PM"
And the call;

Code: Select all

    text "[clock]" xalign 0.035 yalign 0.20 size 19 
When clicking on an event this is executed :

Code: Select all

        $ minutes += 60

The script is suppose to loop at

Code: Select all

if minutes > 1380:
        $ minutes = 0
but instead it just crashes after 11:00 PM
Last edited by Verstehen on Sun Sep 15, 2013 7:24 pm, edited 1 time in total.

User avatar
PyTom
Ren'Py Creator
Posts: 15445
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: Clock loop isn't working, anyone know why?

#2 Post by PyTom » Sun Sep 15, 2013 7:09 pm

If minutes is > 1380, then minutes is changed, but clock is not set. You probably want:

Code: Select all

    if minutes > 1380:
        $ minutes = 0
    
    if minutes == 0:
        $ clock = "12:00 AM"
    elif minutes == 60:
        $ clock = "1:00 AM"
    elif minutes == 120:
        ...
Although I'd think code like:

Code: Select all

python:
    minutes = minutes % 1440
    hour = minutes // 60 % 12
    if hour == 0:
        hour = 12

    if minutes < 720:
        clock = "{}:{:02d} AM".format(hour, minutes % 60)
    else:
        clock = "{}:{:02d} PM".format(hour, minutes % 60)
is cleaner.
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
Verstehen
Newbie
Posts: 10
Joined: Sun Sep 15, 2013 5:40 pm
Contact:

Re: Clock loop isn't working, anyone know why?

#3 Post by Verstehen » Sun Sep 15, 2013 7:24 pm

Thanks a ton. It's working now. Still a bit new with python and it's taking me a bit to get use to this.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]