'GameTime' object has no attribute 'period'

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
mutsuns
Newbie
Posts: 2
Joined: Fri Oct 19, 2018 7:38 pm
Contact:

'GameTime' object has no attribute 'period'

#1 Post by mutsuns »

I'm trying to add a day mechanic in my game. The beginning runs smoothly, but this error (https://prnt.sc/lbm474) comes up at one point.

Here are the codes I used:

Code: Select all

    init python:
        import datetime
        class GameTime(object):
            def __init__(self, dt="Jan 01 2018"):
                self._dt = datetime.datetime.strptime( dt, "%d %b %Y" )
            def alter(self, **kwargs):
                if not kwargs:
                    kwargs = {'hours':6}
                self._dt += datetime.timedelta( **kwargs )
            def __repr__(self):
                return _strftime("%A", self._dt.timetuple())
        @property
        def period(self):
                return [ k[-1] for k in (
                (0,1,2,3,4,5, "Morning"),
                (6,7,8,9,10,11, "Noon"),
                (12,13,14,15,16,17, "Evening"),
                (18,19,20,21,22,23, "Night") ) if self._dt.hour in k ][0]


    default gt = GameTime("24 Sep 2018")
and

Code: Select all

	menu time_loop:
        "Today is [gt], it is [gt.period]."

        "Next period.":
            $ gt.alter()
            jump time_loop

        "Next day.":
            "Is it morning yet?"
            $ gt.alter( days=1, hours=-gt._dt.hour)
            jump time_loop

        "Break Loop":
            pass

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: 'GameTime' object has no attribute 'period'

#2 Post by trooper6 »

def period is not indented properly...so it isn't in the GameTime class. Indent that whole section another 4 spaces.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Post Reply

Who is online

Users browsing this forum: tim640