[SOLVED] Real-Time Progression

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
HappyBot
Newbie
Posts: 4
Joined: Sun Feb 25, 2018 10:46 am
Contact:

[SOLVED] Real-Time Progression

#1 Post by HappyBot »

Hello! Is there a way to limit how the story progresses based on actual time progression? (Ex. X character goes to sleep, you have to wait for X hours until they wake up so you can progress.) I'd need it to be able to calculate the time even when you close the game (so I'd just assume it'd use the computer's time to calculate how much time has passed since you last closed it to when you open it up again)

I know you can import the time using this:

Code: Select all

init:
    $ import time
    $ year, month, day, hour, minute, second, dow, doy, dst = time.localtime()
and that you can time events such as these based on the current date:

Code: Select all

if month == 12 and day == 25:
    e "Merry Christmas!"
Which works great for some timed events I'd like to do for certain dates, but I'm unsure how to use it to calculate how much time has passed since you last closed the game. If anyone knows how to code this, it'd be much appreciated! I've been looking in the forums, but haven't found a way to do it/figure it out.
Last edited by HappyBot on Mon Feb 26, 2018 9:42 am, edited 1 time in total.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2399
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Real-Time Progression

#2 Post by Ocelot »

You can use quit special label to detect when user is trying to exit the game and store time in persistent variable:

Code: Select all

label quit:
    $ persistent.last_exit = time.time()
< < insert Rick Cook quote here > >

HappyBot
Newbie
Posts: 4
Joined: Sun Feb 25, 2018 10:46 am
Contact:

Re: Real-Time Progression

#3 Post by HappyBot »

Oooh, that will definitely come in handy! Sorry for asking, but I'm not too good in the coding aspects of things, how do I tell Renpy that I want it to calculate how much time has passed (x minutes/hours) from the time of the persistent.last_exit so that if you've met them you'll jump to the next label in the story?

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: Real-Time Progression

#4 Post by xavimat »

EDIT: See my next post for an example that (maybe) meets your needs.

Some points I need to raise:

1. Be really careful with this feature. You want to create a game for the FUN of the player, not to annoy them. I'll fly away from games that set this kind of blocks and requirements. I want to play your game, not to organize my schedule according to it.

2. Ocelot's solution could be useful or not, according to how you use it.
For example, you can simply, store the time.time() at one point of your game, and compare it with the persistent.last_exit to have the exact amount of seconds of difference (divide by 3600 to have hours).
BUT: (there is a huge but)
- persistent is the same for every saved game in your game. If I start the game again, the persistent time will be the last_exit. In a normal VN it makes no sense to compare the time when another player, in another play has quit.
- persistent.last_time will be updated every time the player quits.
For example, if you set a minimum of 2 hours "from the last quit", if I open again the game 1 hour and 55 minutes after, check that I can't still get the new option, and quit the game, I'll need another 2 hours to wait.

3. I won't use persistent here. Every play should be different (I'm assuming a normal VN, maybe your game has a total different structure).
I won't use the quit label neither, I think you could check the last "save" not the last "quit", and use the special label after_load, to check the time that has passed from the last save.
Or better, a variable that stores the time (the real time) when the X character goes to sleep, and then compares it with the time when the player reaches the point of the game where the hidden label could be unblocked.


I use a date control in my program, but it works differently. It calculates what day is "today" based on a date in the past.
It's not what you want, but maybe it gives you ideas.
I have a dictionary that stores how many XP points the player has done every day.
The code is, more or less:

Code: Select all

default today = 0
default days = 0

init python:
    from datetime import date

label start:
    $ tempus_fugit = date.today() - date(2017, 03, 22)
    $ today = tempus_fugit.days
    # ...

label after_load:
    $ tempus_fugit = date.today() - date(2017, 03, 22)
    $ new_today = tempus_fugit.days
    $ days = new_today - today
    return
Last edited by xavimat on Sun Feb 25, 2018 1:02 pm, edited 1 time in total.
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
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: Real-Time Progression

#5 Post by xavimat »

Maybe this meets your needs:

Code: Select all

default now = 0
default eileen_goes_to_sleep = 0
default NAP_TIME = 7200  # Seconds

init python:
    import time

label start:
    scene bg house
    "Me" "I'm looking for Eileen."
    $ eileen_goes_to_sleep = time.time()
    "Mother" "Oh, sorry. She has just gone to bed."
    "Me" "Don't worry. I'll wait."
    "Mother" "Mmmm. As you wish. Better take a good book... May I suggest 'The Lord of the Rings'?"
    jump waiting_loop

label waiting_loop:
    $ now = time.time()
    $ wait = eileen_goes_to_sleep + NAP_TIME - now

    if wait > 0:
        "You need to wait [wait] seconds."
        "How is Frodo doing?"
        # You can save the game here, and load it again, or not.
        # It'll work the same.
        jump waiting_loop

    show eileen with dissolve
    
    "Eileen" "Hey! Are you waiting for me?"
    "Eileen" "I'm sorry, I'm busy today."
    
    scene black with fade
    centered "GAME OVER"
    return
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)

HappyBot
Newbie
Posts: 4
Joined: Sun Feb 25, 2018 10:46 am
Contact:

Re: Real-Time Progression

#6 Post by HappyBot »

Thank you very much xavimat! (: It works to perfection! Don't worry I don't plan to abuse the feature haha, I have a specific idea in mind and I will sure to take your advice about not making it taxing on the player to play!

Post Reply

Who is online

Users browsing this forum: Andredron