[solved] Doubt about "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
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

[solved] Doubt about "real time"?

#1 Post by Nanahs »

I'm using this code on my game to show the real time:

Code: Select all

init python:
    import time
    def mytime(st, at):
        return Text(time.strftime('%H:%M'), size=30), 0
image mytimes = DynamicDisplayable(mytime)
I'm also using a messaging system. And I wanted is to show the time the player received the message.

Let's just say that when the person was playing it was 13:53.
If I add in the message "{show image=mytimes}" it will show what time it is the moment you click the message. But as time goes by, the clock will abviously keep changing. "13:53" will become 13:54, 13:55, etc.

Is there a way I can "freeze" the time the person received the message?
Like, if it was 13:53 when I clicked the messsage, it will keep showing "13:53" in the message.

Thank you :)
Last edited by Nanahs on Tue Oct 30, 2018 6:07 pm, edited 1 time in total.

DannX
Regular
Posts: 99
Joined: Mon Mar 12, 2018 11:15 am
Contact:

Re: Doubt about "real time"?

#2 Post by DannX »

You should be able to simply convert the time to a string and store it in a variable, I don't know how your messaging system is coded so I can't give you exact advice but, this is a way to do it:

Code: Select all

time_received = str(time.strftime('%H:%M')) 

User avatar
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

Re: Doubt about "real time"?

#3 Post by Nanahs »

DannX wrote: Fri Oct 19, 2018 8:45 am You should be able to simply convert the time to a string and store it in a variable, I don't know how your messaging system is coded so I can't give you exact advice but, this is a way to do it:

Code: Select all

time_received = str(time.strftime('%H:%M')) 
Thank you!! :)

I'm using this code, from the first messenger (viewtopic.php?f=51&t=50153)

Code: Select all

# Экран сообщения
screen telegram():
    frame background "messenger/back.png" xysize (700,975) align (0.9,.5):
        frame background None xysize (560, 810) align (0.5,0.58):
            viewport id "vp_msg" mousewheel True  yadjustment yadj:
                vbox spacing 8 xsize 550 xalign 0.4 box_reverse True:
                    for message in m_msg[::-1]:
                        $ who, txt, sound = message
                        $ xgn = 0.0 if who else 1.0
                        if sound:
                            imagebutton auto "messenger/sound_%s.png" xalign xgn action Play("sound", sound)
                        else: 
                            button xalign xgn xmaximum 700 xpadding 20 ypadding 10 background Frame("messenger/box.png", 25, 25):
                                text "%s"%(txt) style "txt_base"
                

        # Стрелка
        imagebutton auto "messenger/arr_%s.png" pos (10, 33) action MainMenu(confirm=True)
        # Ползунок прокрутки
        vbar value YScrollValue("vp_msg") style "bar_vert"
And I was trying to add the time inside the message box:

Code: Select all

    python:    
        msg(" text and time here")

User avatar
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

Re: Doubt about "real time"?

#4 Post by Nanahs »

I'm trying to do it, but the time keeps progressing :?:
I wanted the time to "freeze". So that if received the message at 9:46, the text will keep showing "9:46" even though real time passes.

User avatar
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

Re: Doubt about "real time"?

#5 Post by Nanahs »

DannX wrote: Fri Oct 19, 2018 8:45 am You should be able to simply convert the time to a string and store it in a variable, I don't know how your messaging system is coded so I can't give you exact advice but, this is a way to do it:

Code: Select all

time_received = str(time.strftime('%H:%M')) 
How should I define that code? I mean, in a code like this one:

Code: Select all

init python:
    import time
    def mytime(st, at):
        return Text(time.strftime('%H:%M'), size=30), 0
image mytimes = DynamicDisplayable(mytime)
It won't stop giving me error messages.
Sorry, I'm still learning :)

DannX
Regular
Posts: 99
Joined: Mon Mar 12, 2018 11:15 am
Contact:

Re: Doubt about "real time"?

#6 Post by DannX »

You need to "attach" the time to the text of the message. I don't understand russian so I can't read the comments, but after some testing I think that what you need to change is the msg() function in messenger.rpy:

Code: Select all

def msg(txt, who=False, sound=False):
    txt += "\n{}".format(str(time.strftime('%H:%M'))) # Add this line before the rest of the function
    store.m_msg.append((who, txt, sound))
    store.yadj.value = store.yadj.range+300
    renpy.restart_interaction()
     if who:
        renpy.play("new_message.mp3", "sound")
    renpy.pause()
This will append a linebreak, and then the current time to the end of the string, the str() is to make sure the text doesn't keep changing as time passes.

User avatar
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

Re: Doubt about "real time"?

#7 Post by Nanahs »

DannX wrote: Wed Oct 24, 2018 3:19 pm You need to "attach" the time to the text of the message. I don't understand russian so I can't read the comments, but after some testing I think that what you need to change is the msg() function in messenger.rpy:

Code: Select all

def msg(txt, who=False, sound=False):
    txt += "\n{}".format(str(time.strftime('%H:%M'))) # Add this line before the rest of the function
    store.m_msg.append((who, txt, sound))
    store.yadj.value = store.yadj.range+300
    renpy.restart_interaction()
     if who:
        renpy.play("new_message.mp3", "sound")
    renpy.pause()
This will append a linebreak, and then the current time to the end of the string, the str() is to make sure the text doesn't keep changing as time passes.
Thank you so much! :D In case I wanted to use this code in a normal text to show what time it is, like:

Code: Select all

label morning3:
    jhon "Goog morning! It's 9:14 now."
How could I use it?

Sorry to make so many questions hah And thank you so much!

DannX
Regular
Posts: 99
Joined: Mon Mar 12, 2018 11:15 am
Contact:

Re: Doubt about "real time"?

#8 Post by DannX »

You can use a variable, like this:

Code: Select all

label morning3:
    python:
        current_time = time.strftime('%H:%M')
     jhon "Goog morning! It's [current_time] now."
Or interpolate it with the same format function like this:

Code: Select all

label morning3:
    $ jhon("Goog morning! It's {} now.".format(time.strftime('%H:%M')))
That last one is shorter, but harder to read and type.

User avatar
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

Re: Doubt about "real time"?

#9 Post by Nanahs »

DannX wrote: Thu Oct 25, 2018 8:39 am You can use a variable, like this:

Code: Select all

label morning3:
    python:
        current_time = time.strftime('%H:%M')
     jhon "Goog morning! It's [current_time] now."
Or interpolate it with the same format function like this:

Code: Select all

label morning3:
    $ jhon("Goog morning! It's {} now.".format(time.strftime('%H:%M')))
That last one is shorter, but harder to read and type.
Thank you! It worked! :)
The only problem is that if the first message is at 15:13, the time endeed will "freeze". But the other following messages will stay stuck at "15:13" as well. Maybe I did something wrong? But that's ok hah

Just one last thing (sorry, I'm asking too much hah). I was trying to change the letter size, so the time wouldn't be as big as the letters. But it's not working.

Code: Select all

def msg(txt, who=False, sound=False):
    txt += "\n{}".format(str(time.strftime('%H:%M'),size=17))
I tried putting the "size=17" in many different places, but it keeps saying "() takes no keyword arguments renpy".
What should I do?

Post Reply

Who is online

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