Checking that age of user is legal

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
Loopaz
Newbie
Posts: 13
Joined: Thu Apr 12, 2018 4:03 am
Completed: ..asking still the same questions!
Projects: Your choice VN
Location: Poland
Contact:

Checking that age of user is legal

#1 Post by Loopaz » Sun Dec 06, 2020 12:07 pm

Hello.
I want to check that player age is legal so

Code: Select all

label date_of_birth:
    today = date.today()
    $ dob.year = renpy.input("Date of birth. Year:", allow ="0123456789" ,length =4)
    $ dob.month = renpy.input("Date of birth. Month:", allow ="0123456789",length= 2)
    $ dob.day = renpy.input("Date of birth. Day:", allow ="0123456789", length= 2)
    
    if dob.month in (1,3,5,7,8) or dob.month in(01,03,05,07,08,10,12):
        if dob.day =< 32:
            cr "Date is invalid"
            jump date_of_birth
    elif dob.month in (4,6,9,11) or dob.month in (04,06,09):
        if dob.day =< 31:
            cr "Date is invalid"
            jump date_of_birth
    else:
        if dob.year % 4 == 0 and (dob.year % 100 != 0 or dob.year % 400 == 0):
            if dob.day =<30:
                cr "Date is invalid"
                jump date_of_birth
            elif dob.day =29:
                cr "Date is invalid" 
                jump date_of_birth
            else:
                age = today.year - dob.year - ((today.month, today.day) < (dob.month, dob.day))
                    if age >= 18:
                        self.adult = True
                        cr "You are too young"
                        jump illegal
                    else:
                        self.adult = False
                        jump legal
I have exeptions error in line today and age. Help
Last edited by Loopaz on Sun Dec 06, 2020 2:43 pm, edited 1 time in total.
"I know that I know nothing" :shock:
"Who ask not stray" :roll:
Bad english talker :|
I don't expect miracle. I expect profesionals :3
or do something right or do not do it at all

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Chcecking that age of user is legal

#2 Post by Per K Grok » Sun Dec 06, 2020 1:47 pm

Loopaz wrote:
Sun Dec 06, 2020 12:07 pm
Hello.
I want to check that player age is legal so

Code: Select all

label date_of_birth:
    today = date.today()
    $ dob.year = renpy.input("Date of birth. Year:", allow ="0123456789" ,length =4)
    $ dob.month = renpy.input("Date of birth. Month:", allow ="0123456789",length= 2)
    $ dob.day = renpy.input("Date of birth. Day:", allow ="0123456789", length= 2)
    
    if dob.month in (1,3,5,7,8) or dob.month in(01,03,05,07,08,10,12):
        if dob.day =< 32:
            cr "Date is invalid"
            jump date_of_birth
    elif dob.month in (4,6,9,11) or dob.month in (04,06,09):
        if dob.day =< 31:
            cr "Date is invalid"
            jump date_of_birth
    else:
        if dob.year % 4 == 0 and (dob.year % 100 != 0 or dob.year % 400 == 0):
            if dob.day =<30:
                cr "Date is invalid"
                jump date_of_birth
            elif dob.day =29:
                cr "Date is invalid" 
                jump date_of_birth
            else:
                age = today.year - dob.year - ((today.month, today.day) < (dob.month, dob.day))
                    if age >= 18:
                        self.adult = True
                        cr "You are too young"
                        jump illegal
                    else:
                        self.adult = False
                        jump legal
I have exeptions error in line today and age. Help

"today" and "age" need to have a "$" at the start of the line.

I think there are other problems as well.
There are a number of things in the the code that looks like objects but maybe just are variables (i.e. "dob.year")?

User avatar
gas
Miko-Class Veteran
Posts: 838
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Chcecking that age of user is legal

#3 Post by gas » Sun Dec 06, 2020 2:18 pm

Not speaking is senseless.
You don't have to check if an user is "minor aged" (the concept vary by nation) but you must have the informed consent of the user that he want to continue even if that thing is not for minors. So, if the dad purse you, you can tell the content was behind a consent wall.

Nothing instead prevent any user to input any possible number, even that kid.

ANYWAY...

Code: Select all

init python:
    from datetime import date

default today = date.today()
label date_of_birth:
    $ y = renpy.input("Date of birth. Year:", allow ="0123456789" ,length =4)
    $ m = renpy.input("Date of birth. Month:", allow ="0123456789",length= 2)
    $ d = renpy.input("Date of birth. Day:", allow ="0123456789", length= 2)
    $ dob_str = "-".join(str(y),str(m),str(d))
    $ dob = date.strptime(dob_str,"Y%-m%-d%")
    $ age = today.year - dob.year
    if today.month < dob.month or (today.month == dob.month and today.day < dob.day):
        $ age -= 1
    if age <18:
        "Please input another set of numbers to play this eroge, thank you!"
        $renpy.full_restart()
    "Welcome to another eroge."
Not tested now, but I've used it so many times it should work.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
Loopaz
Newbie
Posts: 13
Joined: Thu Apr 12, 2018 4:03 am
Completed: ..asking still the same questions!
Projects: Your choice VN
Location: Poland
Contact:

Re: Chcecking that age of user is legal

#4 Post by Loopaz » Sun Dec 06, 2020 3:33 pm

gas wrote:
Sun Dec 06, 2020 2:18 pm
Not speaking is senseless.
You don't have to check if an user is "minor aged" (the concept vary by nation) but you must have the informed consent of the user that he want to continue even if that thing is not for minors. So, if the dad purse you, you can tell the content was behind a consent wall.

Nothing instead prevent any user to input any possible number, even that kid.

ANYWAY...

Code: Select all

init python:
    from datetime import date

default today = date.today()
label date_of_birth:
    $ y = renpy.input("Date of birth. Year:", allow ="0123456789" ,length =4)
    $ m = renpy.input("Date of birth. Month:", allow ="0123456789",length= 2)
    $ d = renpy.input("Date of birth. Day:", allow ="0123456789", length= 2)
    $ dob_str = "-".join(str(y),str(m),str(d))
    $ dob = date.strptime(dob_str,"Y%-m%-d%")
    $ age = today.year - dob.year
    if today.month < dob.month or (today.month == dob.month and today.day < dob.day):
        $ age -= 1
    if age <18:
        "Please input another set of numbers to play this eroge, thank you!"
        $renpy.full_restart()
    "Welcome to another eroge."
Not tested now, but I've used it so many times it should work.
There is a problem with join line. return error
I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/IntroductionDay.rpy", line 109, in script
$ dob_str = "-".join(str(y),str(m),str(d))
File "game/IntroductionDay.rpy", line 109, in <module>
$ dob_str = "-".join(str(y),str(m),str(d))
TypeError: join() takes exactly one argument (3 given)
Anyway i want to make a birthday of player in game
do i use y or dob.year
"I know that I know nothing" :shock:
"Who ask not stray" :roll:
Bad english talker :|
I don't expect miracle. I expect profesionals :3
or do something right or do not do it at all

Post Reply

Who is online

Users browsing this forum: Alex, nyeowmi