Page 1 of 1

Regards Python execution pause for a certain amount of seconds

Posted: Tue May 11, 2021 2:55 pm
by andriodmactemporary
Here from the code how to pause the code execution for a certain amount of seconds after each line of execution.
If I employ this method program combining all the seconds (2+2+2 = 6 seconds) and pausing the program only once for 6 seconds.

But, I need to pause the program 2 seconds after appending a new message to the array.

This means this has to be like taking time to get a reply message from the receiver.

Code: Select all

import time
persons[selectedPerson["index"]]["chatHistory"].append({'type' : 'forward-message', 'message' : text})

                time.sleep(2)

                persons[selectedPerson["index"]]["chatHistory"].append({'type' : 'reply-message', 'message' : 'Fine'})

               time.sleep(2)

                persons[selectedPerson["index"]]["chatHistory"].append({'type' : 'forward-message', 'message' : "Let's meet somewhere"})

                time.sleep(2)

                persons[selectedPerson["index"]]["chatHistory"].append({'type' : 'reply-message', 'message' : 'Shop or Office'})
                persons[selectedPerson["index"]]["chatHistory"].append({'type' : 'reply-image', 'imagePath' : 'Shop.png'})
                persons[selectedPerson["index"]]["chatHistory"].append({'type' : 'reply-image', 'imagePath' : 'Office.jpg'})

Re: Regards Python execution pause for a certain amount of seconds

Posted: Tue May 11, 2021 3:03 pm
by Ocelot
Well, this code actually works exactly as you want. If you were to inspect list values you would see that they are exactly what you would expect at any given moment.

What you really see is that you probaly do not see any screens redrawing. This is because nothing in the code is telling RenPy "user might notice if screens are not redrawn, get to it". You need to cause an interaction, and time module, not being part of RenPy would not do that.

You probably want to use renpy.pause() function instead.

Re: Regards Python execution pause for a certain amount of seconds

Posted: Tue May 11, 2021 4:30 pm
by andriodmactemporary
Ocelot wrote: Tue May 11, 2021 3:03 pm Well, this code actually works exactly as you want. If you were to inspect list values you would see that they are exactly what you would expect at any given moment.

What you really see is that you probaly do not see any screens redrawing. This is because nothing in the code is telling RenPy "user might notice if screens are not redrawn, get to it". You need to cause an interaction, and time module, not being part of RenPy would not do that.

You probably want to use renpy.pause() function instead.
I have also tried renpy.pause() it is also providing same functionality has time.sleep().

Re: Regards Python execution pause for a certain amount of seconds

Posted: Wed May 12, 2021 2:45 pm
by Ocelot
Is this a part of function or just written in script? Is it a part of a single Python statement?

Re: Regards Python execution pause for a certain amount of seconds

Posted: Thu May 13, 2021 4:58 am
by andriodmactemporary
Ocelot wrote: Wed May 12, 2021 2:45 pm Is this a part of function or just written in script? Is it a part of a single Python statement?
It is wrapped under python block.

Re: Regards Python execution pause for a certain amount of seconds

Posted: Thu May 13, 2021 5:04 am
by Ocelot
Can you replace it with a series of one-line Python statements (and use renpy.pause) and check if it fixes the problem. IIRC python blocks are considered single statement, so there could be your problem.

Re: Regards Python execution pause for a certain amount of seconds

Posted: Thu May 13, 2021 10:25 am
by andriodmactemporary
Ocelot wrote: Thu May 13, 2021 5:04 am Can you replace it with a series of one-line Python statements (and use renpy.pause) and check if it fixes the problem. IIRC python blocks are considered single statement, so there could be your problem.
No use, the same problem is occurring it is waiting entirely for 6 seconds and redrawing the screen.

Here what I have done :

Replaced :-

python:
persons[selectedPerson["index"]]["chatHistory"].append({'type' : 'forward-message', 'message' : text})

time.sleep(2)

persons[selectedPerson["index"]]["chatHistory"].append({'type' : 'reply-message', 'message' : 'Fine'})

time.sleep(2)

persons[selectedPerson["index"]]["chatHistory"].append({'type' : 'forward-message', 'message' : "Let's meet somewhere"})

time.sleep(2)

With :-

$persons[selectedPerson["index"]]["chatHistory"].append({'type' : 'forward-message', 'message' : text})

$renpy.pause(2)

$persons[selectedPerson["index"]]["chatHistory"].append({'type' : 'reply-message', 'message' : 'Fine'})

$renpy.pause(2)

$persons[selectedPerson["index"]]["chatHistory"].append({'type' : 'forward-message', 'message' : "Let's meet somewhere"})

$renpy.pause(2)