Clock not updating [still not solved-small glitch]

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.
Message
Author
SundownKid
Lemma-Class Veteran
Posts: 2299
Joined: Mon Feb 06, 2012 9:50 pm
Completed: Icebound, Selenon Rising Ep. 1-2
Projects: Selenon Rising Ep. 3-4
Organization: Fastermind Games
Deviantart: sundownkid
Location: NYC
Contact:

Clock not updating [still not solved-small glitch]

#1 Post by SundownKid »

So... I updated the clock cookbook recipe a while back to use screen language. Except that when I actually tried to use it in my own game, I realized it didn't work. The clock refuses to update unless I reload the game manually.

Basically - is there any way to update the clock so that it goes to the right position? Added bonus if there is a way to have it "move" to the right position (having the hands rotate from the current time to the next defined time).

http://www.renpy.org/wiki/renpy/doc/coo ... alog_Clock
Last edited by SundownKid on Sat Dec 20, 2014 5:50 pm, edited 3 times in total.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Clock not updating

#2 Post by xela »

I thought we had a udd for this, what happened? I am on android right now so I can't help :(
Like what we're doing? Support us at:
Image

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: Clock not updating

#3 Post by trooper6 »

I just double checked, and my UDD version of the analogue clock is still working fine in the most current version of Renpy. You could check your code versus mine to see what might be going on?

http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
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
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Clock not updating

#4 Post by xela »

Version shouldn't matter for udds. It's odd that we are trying to use a screen for something that we have udd for instead of using it or improving it.

I'll get to my pc in half an hour and take a look at it.
Like what we're doing? Support us at:
Image

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: Clock not updating

#5 Post by trooper6 »

Maybe Sundownkid didn't know about my UDD?
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
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Clock not updating

#6 Post by xela »

trooper6 wrote:Maybe Sundownkid didn't know about my UDD?
Maybe...

I am going to take a look if it can be done with a screen as well without sh!tty code. Right now all of my ideas for it mean code that shouldn't be suggested in wiki/cookbook. Still, we have very few udd examples so it might be wise to clean it up a bit and put it in the wiki.
Like what we're doing? Support us at:
Image

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Clock not updating

#7 Post by xela »

Note 1: In the wiki, files you get from downloading the images are different from the files in the code.
Note 2: In the wiki, rotate transforms are not defines correctly so arrows are always not in the middle of the clock :(
Like what we're doing? Support us at:
Image

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: Clock not updating

#8 Post by xavimat »

SundownKid wrote:So... I updated the clock cookbook recipe a while back to use screen language. Except that when I actually tried to use it in my own game, I realized it didn't work. The clock refuses to update unless I reload the game manually.

Basically - is there any way to update the clock so that it goes to the right position? Added bonus if there is a way to have it "move" to the right position (having the hands rotate from the current time to the next defined time).

http://www.renpy.org/wiki/renpy/doc/coo ... alog_Clock
This works for me:

Code: Select all

screen clock(minutes=minutes):
    frame background None at alpha_dissolve:
        xmaximum 250 ymaximum 250
        align (.98, .02)
        add "clock_2"
        add "clock_1" align (.44, .44) rotate (minutes*0.5)
        add "clock" align (.44, .44) rotate (minutes*6)
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)

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Clock not updating

#9 Post by xela »

xavimat wrote:
SundownKid wrote:So... I updated the clock cookbook recipe a while back to use screen language. Except that when I actually tried to use it in my own game, I realized it didn't work. The clock refuses to update unless I reload the game manually.

Basically - is there any way to update the clock so that it goes to the right position? Added bonus if there is a way to have it "move" to the right position (having the hands rotate from the current time to the next defined time).

http://www.renpy.org/wiki/renpy/doc/coo ... alog_Clock
This works for me:

Code: Select all

screen clock(minutes=minutes):
    frame background None at alpha_dissolve:
        xmaximum 250 ymaximum 250
        align (.98, .02)
        add "clock_2"
        add "clock_1" align (.44, .44) rotate (minutes*0.5)
        add "clock" align (.44, .44) rotate (minutes*6)
We're not quick-fixing someone problem here, we're providing (hopefully decently coded and useful) examples to Ren'Py users...

1) Why frame and not a fixed?
2) Why not write maximum instead of x/y maximums?
3) What if they change the clock size and your aligns are frecked? Do they manually look for the right values? There is an argument to auto correct for this in in ATL called rotate_pad, use that.

My version:

Code: Select all

image hours = "hours.png" # Short Clockhand
image minutes = "minutes.png" # Long Clockhand
image clock = "clock.png" # Clockface

transform rotate_by(start, end, t):
    rotate_pad True
    subpixel True
    rotate start
    linear t rotate end
    
transform alpha_dissolve:
    # This is to fade in the clock.
    on show:
        alpha 0.0
        linear 0.5 alpha 1.0
    on hide:
        linear 0.5 alpha 0
        
init python:
    def uc(minutes, t=0):
        """
        Update clock function. Allows for animation or instant update depending on positional arguments provided.
        Example: Update without animation: $ uc(550).
        Example: Update with animation: $ uc(1550, 4) will animate to minute 1550, animation will take 4 seconds.
        """
        if not hasattr(store, "minutes"):
            store.minutes = 0
        start = store.minutes
        store.minutes = minutes
        renpy.show_screen("clock", start, store.minutes, t)
        
screen clock(start, end, t):
    fixed:
        at alpha_dissolve
        xysize(120, 120) # size of clock graphic (Set to the size of the clock image)
        align (0.99, 0.02) # placement on screen
        add "clock"
        add "hours" at rotate_by(start*0.5, end*0.5, t) align (0.5, 0.5)
        add "minutes" at rotate_by(start*6, end*6, t) align (0.5, 0.5)
    
label start:
    $ uc(0)
    pause
    $ uc(100)
    pause
    $ uc(200, 2)
    pause
*That said, this should prolly be a UDD with more/better options...
Like what we're doing? Support us at:
Image

SundownKid
Lemma-Class Veteran
Posts: 2299
Joined: Mon Feb 06, 2012 9:50 pm
Completed: Icebound, Selenon Rising Ep. 1-2
Projects: Selenon Rising Ep. 3-4
Organization: Fastermind Games
Deviantart: sundownkid
Location: NYC
Contact:

Re: Clock not updating

#10 Post by SundownKid »

My bad- that was my attempt to make it screen language but I didn't realize that such coding would only update once. I will modify it once the issue's fixed.

EDIT: It works great now, but it seems to be unable to hide and show the clock. Basically, I want to be able to hide the clock during cutscenes. So, is there any way to prevent it from always showing it?

Also, I have a "digital" style clock next to the analog one for convenience. But, is there any way to have the digital clock set the exact time extrapolated simply from the minutes variable?

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Clock not updating

#11 Post by xela »

SundownKid wrote:EDIT: It works great now, but it seems to be unable to hide and show the clock. Basically, I want to be able to hide the clock during cutscenes. So, is there any way to prevent it from always showing it?
Hide:

Code: Select all

hide screen clock
Show again (without changing the time, assumes minutes were set at some point before):

Code: Select all

$ hs(minutes)
SundownKid wrote:But, is there any way to have the digital clock set the exact time extrapolated simply from the minutes variable?

Code: Select all

    def min_to_string():
        m = store.minutes
        if m > 0:
            return ":".join([str((m // 60) % 24), str(m % 60)])
        else:
            return "0:0"
Add to your screen:

Code: Select all

    text ("%s"%min_to_string()) align (0.1, 0.1)
Change 24 to 12 if you want the clock to go up to 12 instead of 24.
Like what we're doing? Support us at:
Image

SundownKid
Lemma-Class Veteran
Posts: 2299
Joined: Mon Feb 06, 2012 9:50 pm
Completed: Icebound, Selenon Rising Ep. 1-2
Projects: Selenon Rising Ep. 3-4
Organization: Fastermind Games
Deviantart: sundownkid
Location: NYC
Contact:

Re: Clock not updating

#12 Post by SundownKid »

I was going to say solved, but there is another glitch that came up. In 12-hour mode, whenever the last 2 numbers of time are 00, it says the time as, say 4:0 instead of 4:00.

EDIT: Also, another problem - is there a way to actually add minutes to the clock without having to define the exact time? For example, let's say I had 3 choices and you could do them one after the other. i couldn't just define a time for each of them because the one you start is not known.

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: Clock not updating [still not solved-small glitch]

#13 Post by trooper6 »

Sundown, have you looked at my UDD? It does all the things you are asking for. Even if you don't want to use it, you can take a bunch of the code for your own purposes.
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

SundownKid
Lemma-Class Veteran
Posts: 2299
Joined: Mon Feb 06, 2012 9:50 pm
Completed: Icebound, Selenon Rising Ep. 1-2
Projects: Selenon Rising Ep. 3-4
Organization: Fastermind Games
Deviantart: sundownkid
Location: NYC
Contact:

Re: Clock not updating [still not solved-small glitch]

#14 Post by SundownKid »

To be honest, i'm not really skilled enough to incorporate your clock code into this one so it works correctly. This code gives me everything I need minus those two issues (one of which isn't in your clock, since it's only analog).

Also, your UDD lacks the realtime clock setting, it seems. The hands don't actually seem to move to the next time, unlike this code they just jump there.

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: Clock not updating [still not solved-small glitch]

#15 Post by trooper6 »

The UDD has a number of different settings.
By placing the UDD on a screen you can hide or show it with the hide/show screen commands.

You can input a specific time.
You can increase the time by a specific number of minutes.
You can set the clock to autorun where it runs in real time starting with the time you set it.
You can set the clock to autorun synced up with the real time.

Since you are going to have a clock screen anyway, you can have the screen, put up my analogue clock in that screen and your digital clock on the same screen.

The tutorial should explain how to do everything you need. All you need to do is take the clock.rpy file and put it in your folder (along with whichever image files you are using), create a clock object in your regular script.rpy file by typing in an init block, for example:
$ myClock = Clock(150, "clockBase", "clockHour", "clockMin", 3, 0)

Then place your myClock to a screen.

The main commands you need to deal with in your script:

To set the time manually.
$ myClock.set_time(4,30)

To add time manually. Use this if you want to jump from one time to the next, i.e. "Ten minutes have passed..." Then you jump forward ten minutes.
$ myClock.add_time(0,10)

To have the clock autorun--though note, because there is no second hand, it runs in real time...which means it will take a full minute for the minute hand to move.
$ myClock.autoclock_run(True)

To turn the outrun off:
$ myClock.autoclock_run(False)

To have the clock synced up to the real time in real life:
$ myClock.realclock_run(True)

To turn that off:
$ myClock.realclock_run(False)

If there is something unclear about the tutorial, let me know how to make it more clear. If there is some other feature you need, let me know and I'll see if I can add it.
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

Post Reply

Who is online

Users browsing this forum: No registered users