Page 1 of 1

Help with Calendar Dates, adding and subtracting

Posted: Mon May 09, 2022 11:06 pm
by Galacksee
Hello Everyone!

I am currently creating a game that will add and subtract time from a calendar date based on the answers given to questions.

I found a few helpful posts here: viewtopic.php?f=8&t=37939
and here: viewtopic.php?t=60773

Unfortunately, both of them seemed to have some issues with the code and would error out when I play tested. I do have a good DOB entry code that works, performs limited validation and at least returns the correct formatted entry here:

Code: Select all

init python:
        import datetime
    $ y = renpy.input("Year of your birth (4 digits):", allow ="0123456789" ,length =4)
    $ m = renpy.input("Month of your birth (2 digits):", allow ="0123456789",length= 2)
    $ d = renpy.input("Day of your birth (2 digits):", allow ="0123456789", length= 2)
    $ dob = "{0}/{1}/{2}".format(m, d, y)
    e "Your DOB is [dob]"
However, now that I see it again, that's just entering numerical values and not really pulling a date. Is there a way I can convert this to a date-represented integer within Renpy? I know it can be done in python but I'm really new at this and unsure how it would integrate into Renpy.

Thank you all in advance for any assistance you can provide!

Re: Help with Calendar Dates, adding and subtracting

Posted: Tue May 10, 2022 6:41 am
by m_from_space
You can just use all the things Python is providing and then show it via renpy screens or dialogue or whatever you wanna do with it.

So just create a date object via:

Code: Select all

import datetime

dob = datetime.datetime(y, m, d)
https://www.w3schools.com/python/python_datetime.asp

Re: Help with Calendar Dates, adding and subtracting

Posted: Tue May 10, 2022 8:54 pm
by Galacksee
Thank you! I actually forgot W3Schools was a thing, haven't used it in about a decade.

Time for more coding goodness!