Python Forum
Get syntax error. Dont understand why
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get syntax error. Dont understand why
#19
Dear Good people.
I am really appreciete your unbelieveble help.
I will not guess
I dont know where i miss something
I'v been tried implement all
I am trying to get the easiest method of formatting for me from @ property
@property
        def ss(self):
            second = "0" + str(self._second)
            return second[-2:]
It is just look like this
"Day: [clk.dd] Time: [clk.hh]:[clk.mm] "
$ clk.addtime(15) 
"Date: [clk.day]/[clk.month]/[clk.year]  Time: [clk.hour]:[clk.minute]"
$ clk.addtime(44640)
But it is still not working
It is far beyond of my abilities of understanding

Today Error

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 49, in script
    $ clk.addtime(0,15,0) # Q   how to able add for ex months? Count? 60x24x31~~44640
  File "game/script.rpy", line 49, in <module>
    $ clk.addtime(0,15,0) # Q   how to able add for ex months? Count? 60x24x31~~44640
  File "game/ReFlow.rpy", line 80, in addtime
    self._weekday = weekdays[weekdays.index(self._weekday)-6]
ValueError: tuple.index(x): x not in tuple

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 49, in script
    $ clk.addtime(0,15,0) # Q   how to able add for ex months? Count? 60x24x31~~44640
  File "D:\Giereczki\renpy-7.2.2-sdk\renpy\ast.py", line 900, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "D:\Giereczki\renpy-7.2.2-sdk\renpy\python.py", line 1930, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/script.rpy", line 49, in <module>
    $ clk.addtime(0,15,0) # Q   how to able add for ex months? Count? 60x24x31~~44640
  File "game/ReFlow.rpy", line 80, in addtime
    self._weekday = weekdays[weekdays.index(self._weekday)-6]
ValueError: tuple.index(x): x not in tuple

Windows-7-6.1.7601-SP1
Ren'Py 7.2.2.491
Your choice 1.0
Fri May 17 12:08:46 2019
The Implements
init python:
    weekdays = ("mon","tue","wed","thu","fri","sat","sun")

    SEASONS = {
    'winter': (11, 12, 1, 2, 3),
    'spring': (4, 5),
    'summer': (6, 7, 8),
    'autumn': (9, 10),
    }

    DAYTIMES = {
    'winter': {
        'midnight': (0, 1),
        'night': (2, 4),
        'dawn': (5, 6),
        'morning': (7, 11),
        'noon': (12, 13),
        'afternoon': (14, 17),
        'dusk': (18, 19),
        'night': (20, 23),
        },
    'spring': {
        'midnight': (0, 1),
        'night': (2, 4),
        'dawn': (5, 6),
        'morning': (7, 11),
        'noon': (12, 13),
        'afternoon': (14, 17),
        'dusk': (18, 19),
        'night': (20, 23),
        },
    'summer': {
        'midnight': (0, 1),
        'night': (2, 4),
        'dawn': (5, 6),
        'morning': (7, 11),
        'noon': (12, 13),
        'afternoon': (14, 17),
        'dusk': (18, 19),
        'night': (20, 23),
        },
    'autumn': {
        'midnight': (0, 1),
        'night': (2, 4),
        'dawn': (5, 6),
        'morning': (7, 11),
        'noon': (12, 13),
        'afternoon': (14, 17),
        'dusk': (18, 19),
        'night': (20, 23),
        },
    }


    class Clock(object):
        def __init__(self , year, month, day, weekday, hour, minute, second, season, daytime):
            self._year = year
            self._month = month
            self._day = day
            self._weekday = weekday
            self._hour = hour
            self._minute = minute
            self._second = second
            self._season = season
            self._daytime = daytime
            
        def addtime(self , hours , minutes , seconds):
            self._second += seconds 
            self._minute += minutes # add minutes
            self._hour += hours

            self._minute += self._second // 60
            self._hour += self._minute // 60
            self._day += self._hour // 24
            
            self._second = self._second % 60
            self._minute = self._minute % 60
            self._hour = self._hour % 24

            self._weekday = weekdays[weekdays.index(self._weekday)-6]
        
            if self._month in (1,3,5,7,8,10,12):
                if self._day > 31:
                    self._day = 1
                    self._month += 1
            elif self._month in (4,6,9,11):
                if self._day > 30:
                    self._day = 1
                    self._month += 1
        #february in leap year
            else :
                # devide by 4
                if (self._year // 4) == 0 :
                    # devide by 100
                    if (self._year // 100) == 0 :
                        # devide by 400
                        if (self._year // 400) == 0 :
                            #leap year
                            __d = 29
                        else:
                            #normal year
                            __d = 28
                    else:
                        #devide by 4 - leap year
                        __d = 29
                else:
                    #normal year
                    __d = 28

                if self._day > __d:
                    self._day = 1
                    self._month += 1
            if self._month > 12:
                self._month = 1
                self._year += 1

        def overlapping_in_range(value, min_val, max_val): 
            if min_val < max_val:
                return min_val <= value < max_val
            elif min_val > max_val:
                return value >= min_val or value < max_val
 
        def get_season(month):
            for season, months in SEASONS.items():
                if month in months:
                    return season
 
        def get_daytime(hour, month):
            # get the current season based on month
            season = get_season(month)
            # addressing DAYTIMES[season] to get the
            # sub-dict.
            for daytime, (mmin, mmax) in DAYTIMES[season].items():
                if overlapping_in_range(hour, mmin, mmax):
                    return daytime
            return ''
        
        def get_weekdays(self):
            if self._month < 3 :
                __m = self._month + 12
                __y = self._year - 1
            else :
                __m = self._month
                __y = self._year
            __weekday = ((__y+__y/4-__y/100+__y/400+(13*__m+8)/5+self._day) % 7) - 1
            self.weekday = weekdays[__weekday]
            return weekdays[__weekday]

               
        
        @property
        def year(self): # day as int
            return self._year
        
        @property
        def yy(self): # minutes as mm.
            year = "0" + str(self._year)
            return year[-2:]
        
        @property
        def month(self): # day as int
            return self._month
        
        @property
        def mn(self): # minutes as mm.
            month = "0" + str(self._month)
            return month[-2:]
            
        @property
        def day(self): # day as int
            return self._day
        
        @property
        def dd(self): # minutes as mm.
            day = "0" + str(self._day)
            return day[-2:]
            
        @property
        def hour(self): # _hour as int
            return self._hour

        @property
        def hh(self): 
            hour = "0" + str(self._hour)
            return hour[-2:] # Q what is doing this 2?

        @property
        def minute(self): # minute as int
            return self._minute

        @property
        def mm(self): # minutes as mm.
            minute = "0" + str(self._minute)
            return minute[-2:]
        
        @property
        def second(self):
            return self._second

        @property
        def ss(self):
            second = "0" + str(self._second)
            return second[-2:]

#def __init__(self , year, month, day, weekday, hour, minute, second, season)   
default clk = Clock(2019, 5, 15, 3, 6, 45, 45, 0, 1)
The way i v been tried to make it

while True:
        "Day: [clk.dd] Time: [clk.hh]:[clk.mm] "
        $ clk.addtime(0,15,0) 
        "Date: [clk.day]/[clk.month]/[clk.year]  Time: [clk.hour]:[clk.minute]"
        $ clk.addtime(10,0,0) 
        "Blow mind"
    return
I give more than one parameter in $ clk.addtime(15) because there was other error about that we have 4 arg and 2 given and propably minutes given?
So i made 3 and occured this error
I bet i make a misteke in add time method? thats it called method
It is soo frustrating to not know what is going on with ur code


In between my mistakes
I am not sure how exectly work overlapping
Do i need do like this?
DAYTIMES = {
    'winter': {
        'midnight': (0, 1),
        'night': (2, 4),
or i can
DAYTIMES = {
    'winter': {
        'midnight': (0, 1),
        'night': ([b]1[/b], 4),
or even
DAYTIMES = {
    'winter': {
        'midnight': (0,0),
        'night': (0, 4),
I did long dict because it was logical for me
if i am wrong tell me

Who wants to be payed for this help?
I bet i am not soo rich Doh

Sincerely, your nooby, beLIEve


Huh

P.S. In line 146 i v been tried with floor and without self._weekday and self.weekday

Anyway how to use tuple Cry

Obviously i would like to have option to show season but i dont know how

The time worked, showed day and time and after boom error
Reply


Messages In This Thread
Clock\Calendar for my game [Renpy] - by beLIEve - May-10-2019, 08:52 AM
Get syntax error. Dont understand why - by beLIEve - May-13-2019, 12:46 AM
RE: Get syntax error. Dont understand why - by beLIEve - May-17-2019, 10:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  World Clock syntax error OscarBoots 1 159 May-03-2024, 05:20 AM
Last Post: snippsat
  Syntax error for "root = Tk()" dlwaddel 15 1,287 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 435 Jan-19-2024, 01:20 PM
Last Post: rob101
  Syntax error while executing the Python code in Linux DivAsh 8 1,685 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,269 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  syntax error question - string mgallotti 5 1,366 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,319 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 938 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  I dont know why my function won't work? MehHz2526 3 1,216 Nov-28-2022, 09:32 PM
Last Post: deanhystad
  Something the code dont work AlexPython 13 2,318 Oct-17-2022, 08:34 PM
Last Post: AlexPython

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020