[SOLVED] My watch is not updated in real time ...

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
CharlieFuu69
Regular
Posts: 30
Joined: Mon Nov 11, 2019 10:32 pm
Projects: Current projects using Ren'Py : "Tears: The First Love!" (Visual Novel at 90%) , "ElectroBasics Electronic Quiz!" (Educative game at 45%).
Location: Chile
Contact:

[SOLVED] My watch is not updated in real time ...

#1 Post by CharlieFuu69 » Tue Dec 10, 2019 1:38 am

Hello!
A few minutes ago it occurred to me to add a real-time clock to the game environment, based on the data of the system where the game is operating. The subject: The minutes are not updated (Indicates the time at which the player entered that scene, and stays there).

I attach the code to see if it can be improved :

Code: Select all

init:  
    $ import time
    $ year, month, day, hour, minute, second, dow, doy, dst=time.localtime()

screen clock():

    frame:
        xalign 0.5
        ypos 0.8
        xsize 200
        ysize 70
        text _("[hour] : [minute]"):
            xalign 0.5
            yalign 0.5 

The coordinates are only for testing so you can ignore them.
What can I do to update it as time goes by? ...
I appreciate your response!
Last edited by CharlieFuu69 on Tue Dec 10, 2019 7:11 pm, edited 1 time in total.

User avatar
PyTom
Ren'Py Creator
Posts: 15893
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: My watch is not updated in real time ...

#2 Post by PyTom » Tue Dec 10, 2019 2:59 am

You'll want to use a DynamicDisplayable.

Code: Select all

init python:
    import datetime

    def wall_time_functon(st, at):
          now = datetime.datetime.now()
          next_minute = (now + datetime.timedelta(minutes=1)).replace(second=0, microsecond=0)
          remaining = next_minute - now
          return Text(now.strftime("%H:%M"), remaining.seconds + remaining.microseconds / 1000000.0

    image wall_time = DynamicDisplayable(wall_time_function)
Your screen will then become:

Code: Select all

screen clock():

    frame:
        xalign 0.5
        ypos 0.8
        xsize 200
        ysize 70
        add wall_time xalign 0.5 yalign 0.5
Updating variables only happens when the variables change and renpy.restart_interaction() is called - and your example doesn't do either.
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
CharlieFuu69
Regular
Posts: 30
Joined: Mon Nov 11, 2019 10:32 pm
Projects: Current projects using Ren'Py : "Tears: The First Love!" (Visual Novel at 90%) , "ElectroBasics Electronic Quiz!" (Educative game at 45%).
Location: Chile
Contact:

Re: My watch is not updated in real time ...

#3 Post by CharlieFuu69 » Tue Dec 10, 2019 1:13 pm

Thanks for the help!!! I will put that code into practice !!!

User avatar
CharlieFuu69
Regular
Posts: 30
Joined: Mon Nov 11, 2019 10:32 pm
Projects: Current projects using Ren'Py : "Tears: The First Love!" (Visual Novel at 90%) , "ElectroBasics Electronic Quiz!" (Educative game at 45%).
Location: Chile
Contact:

Re: My watch is not updated in real time ...

#4 Post by CharlieFuu69 » Tue Dec 10, 2019 1:41 pm

I get an "Error in code analysis"

Invalid syntax

image wall_time = DynamicDisplayable(wall_time_funcion)

Just when the "=" symbol begins

I apologize ... I am novice

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: My watch is not updated in real time ...

#5 Post by Remix » Tue Dec 10, 2019 3:09 pm

Unindent it

Code: Select all

init python:
    import datetime

    def wall_time_functon(st, at):
          now = datetime.datetime.now()
          next_minute = (now + datetime.timedelta(minutes=1)).replace(second=0, microsecond=0)
          remaining = next_minute - now
          return Text(now.strftime("%H:%M"), remaining.seconds + remaining.microseconds / 1000000.0

# bring this next line out of the python block
image wall_time = DynamicDisplayable(wall_time_function)
Frameworks & Scriptlets:

User avatar
CharlieFuu69
Regular
Posts: 30
Joined: Mon Nov 11, 2019 10:32 pm
Projects: Current projects using Ren'Py : "Tears: The First Love!" (Visual Novel at 90%) , "ElectroBasics Electronic Quiz!" (Educative game at 45%).
Location: Chile
Contact:

Re: My watch is not updated in real time ...

#6 Post by CharlieFuu69 » Tue Dec 10, 2019 4:22 pm

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 73, in script
    with fade
  File "game/screens.rpy", line 118, in execute
    screen clock():
  File "game/screens.rpy", line 118, in execute
    screen clock():
  File "game/screens.rpy", line 120, in execute
    frame:
  File "game/screens.rpy", line 125, in execute
    add wall_time xalign 0.5 yalign 0.5
NameError: name 'wall_time' is not defined

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 73, in script
    with fade
  File "E:\@CharlieFuu69 OT-SUR\Motor Ren'Py\renpy-7.3.2-sdk\renpy\ast.py", line 1387, in execute
    renpy.exports.with_statement(trans, paired)
  File "E:\@CharlieFuu69 OT-SUR\Motor Ren'Py\renpy-7.3.2-sdk\renpy\exports.py", line 1592, in with_statement
    return renpy.game.interface.do_with(trans, paired, clear=clear)
  File "E:\@CharlieFuu69 OT-SUR\Motor Ren'Py\renpy-7.3.2-sdk\renpy\display\core.py", line 2248, in do_with
    clear=clear)
  File "E:\@CharlieFuu69 OT-SUR\Motor Ren'Py\renpy-7.3.2-sdk\renpy\display\core.py", line 2699, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "E:\@CharlieFuu69 OT-SUR\Motor Ren'Py\renpy-7.3.2-sdk\renpy\display\core.py", line 3091, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "E:\@CharlieFuu69 OT-SUR\Motor Ren'Py\renpy-7.3.2-sdk\renpy\display\core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "E:\@CharlieFuu69 OT-SUR\Motor Ren'Py\renpy-7.3.2-sdk\renpy\display\core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "E:\@CharlieFuu69 OT-SUR\Motor Ren'Py\renpy-7.3.2-sdk\renpy\display\core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "E:\@CharlieFuu69 OT-SUR\Motor Ren'Py\renpy-7.3.2-sdk\renpy\display\core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "E:\@CharlieFuu69 OT-SUR\Motor Ren'Py\renpy-7.3.2-sdk\renpy\display\core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "E:\@CharlieFuu69 OT-SUR\Motor Ren'Py\renpy-7.3.2-sdk\renpy\display\screen.py", line 430, in visit_all
    callback(self)
  File "E:\@CharlieFuu69 OT-SUR\Motor Ren'Py\renpy-7.3.2-sdk\renpy\display\core.py", line 3091, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "E:\@CharlieFuu69 OT-SUR\Motor Ren'Py\renpy-7.3.2-sdk\renpy\display\screen.py", line 440, in per_interact
    self.update()
  File "E:\@CharlieFuu69 OT-SUR\Motor Ren'Py\renpy-7.3.2-sdk\renpy\display\screen.py", line 625, in update
    self.screen.function(**self.scope)
  File "game/screens.rpy", line 118, in execute
    screen clock():
  File "game/screens.rpy", line 118, in execute
    screen clock():
  File "game/screens.rpy", line 120, in execute
    frame:
  File "game/screens.rpy", line 125, in execute
    add wall_time xalign 0.5 yalign 0.5
  File "<screen language>", line 125, in <module>
NameError: name 'wall_time' is not defined

Windows-8-6.2.9200
Ren'Py 7.3.2.320
Tears : The First Love! v2.01_alpha
Tue Dec 10 17:15:20 2019
Remix The code tells me that it's not defined ... I think I'm getting a little dizzy :lol:

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: My watch is not updated in real time ...

#7 Post by Remix » Tue Dec 10, 2019 5:24 pm

try just

Code: Select all

 add DynamicDisplayable(wall_time_function) 
Frameworks & Scriptlets:

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

Re: My watch is not updated in real time ...

#8 Post by Alex » Tue Dec 10, 2019 5:45 pm

CharlieFuu69 wrote:
Tue Dec 10, 2019 1:41 pm
I get an "Error in code analysis"

Invalid syntax

image wall_time = DynamicDisplayable(wall_time_funcion)

Just when the "=" symbol begins

I apologize ... I am novice
There was a little typo in the name of the function...
Try

Code: Select all

init python:
    import datetime
    def wall_time_function(st, at):
        now = datetime.datetime.now()
        next_minute = (now + datetime.timedelta(minutes=1)).replace(second=0, microsecond=0)
        remaining = next_minute - now
        return Text(now.strftime("%H:%M"), remaining.seconds + remaining.microseconds / 1000000.0), 0.1
        

image wall_time = DynamicDisplayable(wall_time_function)
https://www.renpy.org/doc/html/displaya ... isplayable

User avatar
CharlieFuu69
Regular
Posts: 30
Joined: Mon Nov 11, 2019 10:32 pm
Projects: Current projects using Ren'Py : "Tears: The First Love!" (Visual Novel at 90%) , "ElectroBasics Electronic Quiz!" (Educative game at 45%).
Location: Chile
Contact:

Re: My watch is not updated in real time ...

#9 Post by CharlieFuu69 » Tue Dec 10, 2019 6:59 pm

Remix wrote:
Tue Dec 10, 2019 5:24 pm
try just

Code: Select all

 add DynamicDisplayable(wall_time_function) 
When booting, another code error

"Invalid syntax"
add DynamicDisplayable → (wall_time_function)

I will try what Alex says ... Back with answers in a minute...

User avatar
CharlieFuu69
Regular
Posts: 30
Joined: Mon Nov 11, 2019 10:32 pm
Projects: Current projects using Ren'Py : "Tears: The First Love!" (Visual Novel at 90%) , "ElectroBasics Electronic Quiz!" (Educative game at 45%).
Location: Chile
Contact:

Re: My watch is not updated in real time ...

#10 Post by CharlieFuu69 » Tue Dec 10, 2019 7:10 pm

Alex wrote:
Tue Dec 10, 2019 5:45 pm
CharlieFuu69 wrote:
Tue Dec 10, 2019 1:41 pm
I get an "Error in code analysis"

Invalid syntax

image wall_time = DynamicDisplayable(wall_time_funcion)

Just when the "=" symbol begins

I apologize ... I am novice
There was a little typo in the name of the function...
Try

Code: Select all

init python:
    import datetime
    def wall_time_function(st, at):
        now = datetime.datetime.now()
        next_minute = (now + datetime.timedelta(minutes=1)).replace(second=0, microsecond=0)
        remaining = next_minute - now
        return Text(now.strftime("%H:%M"), remaining.seconds + remaining.microseconds / 1000000.0), 0.1
        

image wall_time = DynamicDisplayable(wall_time_function)
https://www.renpy.org/doc/html/displaya ... isplayable
Thanks Alex !!! ... Now it works perfect !. I will mark the post as solved

Post Reply

Who is online

Users browsing this forum: Google [Bot]