Ren'Py I don't understand this lol

Thierry29

Member
Jun 3, 2017
128
59
hello hello :)

So here a big noob, yes me !
I'm very bad at coding so to search a solution.... Why don't using an AI to try some code.... Well my bad, code don't work lol !
the screen don't show in game and it's just this code in a new "project" for testing.

So what the AI did wrong ? (AI chat, a free AI)
Renpy 8.1 and coding with visual studio code
code in script and screen in my screen

in game ; Exception: Unknow text tag (current_date.strftime('%A, %B %d, %Y %H:%M') (%d in blue color don't know why, the rest in orange)




Python:
define m = Character('MC', color="#c8ffc8")

init python:
    import datetime
    current_date = datetime.datetime(2024, 1, 1, 9, 0)
    time_delta = datetime.timedelta(minutes=1)
    class AdvanceTime(Action):
        def __call__(self):
            global current_date
            current_date += time_delta
            renpy.notify("Time advanced to {}".format(current_date.strftime('%H:%M')))
    class AdvanceDate(Action):
        def __call__(self):
            global current_date
            current_date += datetime.timedelta(days=1)
            renpy.notify("Date advanced to {}".format(current_date.strftime('%A, %B %d, %Y %H:%M')))

   
$ renpy.repeat(1.0, AdvanceTime)


# Le jeu commence ici
label start:
    m"bla bla bla"
    m"bla bla bla"
    m"Is the screen work ?"
    show screen time_screen
    
    menu:
        "screen work":
            mc"yeahhh"
        "screen don't work":
            mc"What the f*ck that IA gived to me ? ARGGGGGGHHHHHH" 
   
    return


screen time_screen:
    text "{current_date.strftime('%A, %B %d, %Y %H:%M')}"
    textbutton "Advance Time" action AdvanceTime()
    textbutton "Advance Date" action AdvanceDate()
 

D.mon

Newbie
Game Developer
Dec 29, 2023
26
173
Out of curiosity, I asked chatgpt to fix it (also free), so you can try it if you want.
I'd recommend to learn bit by bit trough video tutorials and google, so that you can learn to understand what you actually do for the game, cause later on it'll get complicated to change things if you don't know what certain code does. It's quite easy to be honest. I've learned a lot like that in a short amount of time.

Here's the corrected Ren'Py code with the issues addressed:

Code:
define m = Character('MC', color="#c8ffc8")

init python:
    import datetime
    current_date = datetime.datetime(2024, 1, 1, 9, 0)
    time_delta = datetime.timedelta(minutes=1)
    
    class AdvanceTime(Action):
        def __call__(self):
            global current_date, time_delta
            current_date += time_delta
            renpy.notify("Time advanced to {}".format(current_date.strftime('%H:%M')))
    
    class AdvanceDate(Action):
        def __call__(self):
            global current_date
            current_date += datetime.timedelta(days=1)
            renpy.notify("Date advanced to {}".format(current_date.strftime('%A, %B %d, %Y %H:%M')))

$ renpy.repeat(1.0, AdvanceTime())

# Le jeu commence ici
label start:
    m "bla bla bla"
    m "bla bla bla"
    m "Is the screen working?"
    show screen time_screen
    
    menu:
        "Screen works":
            mc "Yeah!"
        "Screen doesn't work":
            mc "What the heck did this AI give to me? ARGGGGGGHHHHHH"
  
    return

screen time_screen:
    text "{current_date.strftime('%A, %B %d, %Y %H:%M')}"
    textbutton "Advance Time" action AdvanceTime()
    textbutton "Advance Date" action AdvanceDate()
Here's a summary of the changes made:

1. Moved the instantiation of `time_delta` into the `init python` block so that it's defined before being used in the `AdvanceTime` class.
2. Added a comma after `global current_date` inside the `AdvanceTime` class's `__call__` method.
3. Fixed indentation for character dialogue lines (`m` statements) in the `start` label.
4. Corrected the punctuation and capitalization in dialogue lines.
5. Fixed the text for the menu options (`"Screen works"` and `"Screen doesn't work"`).
6. Fixed indentation for the dialogue lines inside the menu options (`mc` statements).
7. Added missing parentheses to the `renpy.repeat()` function call.
8. Changed `"screen work"` and `"screen don't work"` to `"Screen works"` and `"Screen doesn't work"` respectively in the menu options.

These changes should make the code run without any syntax errors and address some formatting issues.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,130
14,809
Why don't using an AI to try some code....
Because AIs codes like idiots and, in top of not understanding what they are doing, they also rarely understand what you actually really want them to do...

The question is more, why come here only after you got a broken code, when there's already so many answers available here ? Yet it's just by searching "time" in the thread titles. I know there's some others, hidden here and there, in less obvious threads.


in game ; Exception: Unknow text tag (current_date.strftime('%A, %B %d, %Y %H:%M')
Well, for once the exception is fucking precise and explicit. "current_date.strftime('%A, %B %d, %Y %H:%M')" is not a valid text tag. There's no needs to be intimidated just because Ren'Py yell at you.
And like you define yourself as a noob, there's no doubt that you took at least a quick look at Ren'Py documentation. So you surely know what text tags are.


(%d in blue color don't know why, the rest in orange)
Because it's the only thing valid in that line... Well, the only with the leading text.


Python:
    text "{current_date.strftime('%A, %B %d, %Y %H:%M')}"
This should be text "{}".format( current_date.strftime('%A, %B %d, %Y %H:%M') )

I really wonder how an AI can have come to that ridiculous syntax. There's no way for it to come from real examples, whatever from Ren'Py or Python.



But seriously, I know that 79flavors will partly disagree with me, but having to use datetime for something as basic is really overkill.
It's only needed if you really want to have a date/time system that follow a real calendar behavior. But 99% of the time, outside of management games, the only thing that will be used is the hour and the day of the time.
Something that only need two variables, one named "hours" and one named "days", and less than ten lines of code:
Python:
init python:

    def advanceTime( increment=1 ):
        store.hours += increment
        while store.hours > 23:
            store.hours -= 24
            store.days += 1

    def dayToday():
        return dayOfTheWeek[store.days % 7]

define dayOfTheWeek = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]
default hours = 8
default days = 0
And your screen would looks like this:
Python:
screen time_screen():   # <-- The '()' aren't here for the decoration, stupid AI !

    vbox:   # <-- Still stupid AI !
        text "{} at {}".format( dayToday(), hours )
        textbutton "+1 Hour" action Function( advanceTime )
        textbutton "+5 Hour" action Function( advanceTime, 5 )
        textbutton "Next day" action SetVariable( "days", days + 1 )
 

Thierry29

Member
Jun 3, 2017
128
59
Out of curiosity, I asked chatgpt to fix it (also free), so you can try it if you want.
well, thank's d.mon I 'll try this corrected code and learn more and more

The question is more, why come here only after you got a broken code, when there's already so many answers available here ?
that's the trick :)
I watched numerous posts, video... But there is so many differents aswers to the same questions, it's ok because
everyone has their own idea of their game.

I posted because I was surprised by the failure of the AI, it was just a test for the fun.
I'm clearly not up to the level to start a project and if I start one, it is not with the aim of doing work. It 'll be just for me :)

The choice of a date system was to follow one years or two, yep a f*ck long and slow grinding game. ^^
1 step: learning with basic stuff = just add a small hud with time system and test the progress of hours and days based on in-game action (take lunch = x time)

2 step: a calendar (with someting like work holidays) based on 2024/2025 (in french paques, grandes vacances, tousaint...)

3 step: some others stuff like inventory, pnj stats....

I will not start a project until I have stable code ^^


Anyway, thank you both D.mon and anne O'nymousfor responding so quickly.

anne O'nymous sorry for making you... grumpy again with this the same question posted again and again but you're clearly a must have for this forum :)

79flavors tutorials are already in my bookmarks with some others posts :) and he/her is less grumpy !! lol
 
  • Like
Reactions: 79flavors

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,559
2,175
But seriously, I know that 79flavors will partly disagree with me, but having to use datetime for something as basic is really overkill.

Nope. I don't disagree at all. It is completely overkill.
I tried it once as a "don't reinvent the wheel" solution. Except, new developers don't need a wheel - they need something that looks like a wheel, without all the complexity of a "real" wheel.

I think at the time I was trying to code something that looked like an iPhone's calendar. So why should I do all the heavy lifting, when the system already has me covered?
Whereas a new developer, especially those with little programming background, just need something that says "morning, afternoon, evening, night" and "Sun, Mon, Tues, Weds, Thurs, Fri, Sat".

And yes, there's a million possible solutions to this one - because it's a simple problem with lots of wiggle room. Really, it comes down to finding a bit of code you "almost" understand and then working on it until it works "enough". I've been there, done that. I went through lots of iterations, each one getting more and more complex. If my solution #4 is making you scratch your head... seek out my solution #2 or #1. It'll be worse, but it'll be simpler.
 
  • Like
Reactions: anne O'nymous

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,130
14,809
But there is so many differents aswers to the same questions, it's ok because
everyone has their own idea of their game.
It's more for the reason gave by 79flavors above: It's something so basic in intent that there's tons of ways to do it.

If you want, it's like writing your name on a piece of paper.
You can use a pencil, a ball-point pen, a fountain pen or a sharpie. You can write it in blue, black, red, green, and few other colors ; I used to use a fountain pen with purple ink for every thing in high school, please, don't judge. You can write in cursive or letterpress. You can put everything in uppercase, just the initials in uppercase, or everything in lowercase. You can put it on the left, the center, or the right, with a more or less top and/or left/right margin. And I'm surely forgetting many other possibilities.
And, strictly speaking, all those ways are valid. There isn't one more efficient or more correct than the others, because what is asked is purely basic.
It's when you starts to goes a bit in depth that some methods can be better than others. If it's for a long time use, a pencil is not the best idea. If it's for a serious document, another color than blue or black aren't ideal. And so on. But all this doesn't prevent you to use your best pen, and take ten minutes to perfectly write your name, even if it's just for something that will end in the trash before the end of the day.

What mean that all the time system examples you can find, here or on Ren'Py official forum, are by default good for what you want. This whatever if it's the basic code I wrote in this thread, or the most advanced one that you can found.
Some will perhaps do way more than what you need, but all will at least do what you need. Some will perhaps be a bit too basic, but not necessarily impossible to deal with.

By example, you can still use my basic approach and have holidays. Just count them in day of the week and weeks, instead of effective days and months:
Python:
init python:

    def isHoliday():
        if int( days / 7 ) == 14 and days % 7 in [0, 1]:
           return "Easter"
        elif 26 < int( days / 7 ) < 36:
           return "summer holidays"
        elif int( days / 7 ) == 44 and days % 7 == 5:
           return "All Saints' Day"
        else:
           return None
Of course, it's not the most efficient way to do it. But it's a good demonstration that it's not because the system itself is basic, that it can't do some marvels.


I posted because I was surprised by the failure of the AI, it was just a test for the fun.
What would surprise me is an AI that give a working code. And I mean a real working code, not one that looks like it works, but will give wrong results once used outside of a really limited context.

I already said it, but when I had to compute a line in Python, I tested AIs, asking for a port of the
Bresenham line algorithm. It's something basic, used since 60 years or so, I know it but why bother when there's surely dozen guys who did the port for me already, and AIs that can surely deal with something as simple :giggle:
Well, whatever AI I asked, and whatever how often I asked, either it wasn't working, or it worked only when the end coordinates are both higher than the starting ones. Want to draw a line from 1,1 to 5,5 ? Okay. Want to draw the line from 5,1 to 1,5 ? You'll get something that don't end where you want, and don't always looks like a straight line...
But who test with something other than 1,1 to 5,5 ? The numbers themselves can vary, but our first thought will always be to use end coordinates that are both higher. So, it's good, we have our working code, we integrate it, we works around it, works on the rest, and hours, or more surely weeks, later, we have to use a 5,1 to 1,5 line, and boom, we discover that we are doomed... Except that we don't know from what part of code come the error, and assume that the AI is probably not the cause.
Well, long story short, don't trust AIs for code, unless you're good enough to see when the code is wrong and why. But if you're that good, why even ask an AI ?
This said, in the end it gave me an idea, and I now have a 18 lines optimized port for the algorithm.


(in french paques, grandes vacances, tousaint...)
Oh god, they are everywhere :eek: :ROFLMAO:
By the way, it's "toussaint".


This being said, I don't remember which one, but among the three threads I linked, one normally have the kind of time system you want for your project.


anne O'nymous sorry for making you... grumpy again [...]
Don't need to be sorry. You assume that I'm not always grumpy, I take this as a compliment :cool:


Really, it comes down to finding a bit of code you "almost" understand and then working on it until it works "enough".
I totally agree.
And, modulo the "works 'enough'" part, god, how programmers life would be easier if we were taught this in college, instead of understanding it the day we are definitively tired to systematically have to come up with new algorithms.


I've been there, done that. I went through lots of iterations, each one getting more and more complex. If my solution #4 is making you scratch your head... seek out my solution #2 or #1. It'll be worse, but it'll be simpler.
Isn't simplicity something relative ? Especially when Python is involved.

You can have a class working like the persistent store with just three lines:
Python:
class whatever():
    def __getattr__( *args):
        return None
It's simple, but in the same time... An object that return the value of its attribute, if the attribute exist, and will return None if it don't exist ? What the fucking fuck is this ?

With Python more than with any other language, you understand the difference between "simple to implement" and "simple to use".
 
  • Like
Reactions: gojira667

osanaiko

Engaged Member
Modder
Jul 4, 2017
2,111
3,392
One more thing to add to this thread:

The amount of renpy code available on the open internet is probably 4-5 orders of magnitude less than the code of more popular languages. So it would be very hard for a generic AI to get enough renpy code examples (especially good quality) to "learn" the patterns.

I would not expect any coding assistant to give good results for renpy.
 

Thierry29

Member
Jun 3, 2017
128
59
helllo ! back again for some advices :)

After somes thinking, I know what I want but I don't know if it's applicable.

Why use datetime ? hummm, to have a February 29 in 2024 !!! That's my base, a full real year.

What I'm trying to achieve:

- screen with date and hour behind a UI like a phone screen, for the moment I use a basic screen with textbuton for training, it's working. UI integration will be later.

- a date triggers an event ex. an anniversary. (if gamedate = xx jump anniversary pnj)

- a hour triggers an event in a rom (if gamedate = yy a pnj is in a room) maybe this requires a schedule.

- an action takes time ex. take a nap = zz minutes, I don't want something linear but to be able to break the rhythm, so not something like 5/10/15/20 etc... but like this addminute(22)

what is needed for this ? a mix between datetime and a calendar or the two of them ?

So far my code is only (don't laugh ! lol I'm still burning my brain) :
base is from 79flavors in an other thread.

Python:
# test d'un code de date et heure.
init python:
    import datetime
    import calendar # futur
    import locale   # ajouter le 02.04.2024 permet au jeu de se baser sur le système pour afficher la date et l'heure en fr
    locale.setlocale(locale.LC_ALL, '')# ajouter le 02.04.2024 active la fonction, fonctionnement confirmé, traduit la date en fr

init python:

    class AdvanceTime(Action): #avance le temps par 1mn just for test
        def __call__(self):
            global gamedate, time_delta #original
            gamedate += datetime.timedelta(minutes=1) #changer le chiffre pour avoir un autre delta
            renpy.notify("Time advanced to {}".format(gamedate.strftime('%H:%M')))


    class AdvanceHour(Action):  # permet d'ajouter un bouton pour changer l'heure dans le screen, fonctionne ajouter le 02.01.2024
        def __call__(self):
            global gamedate
            gamedate += datetime.timedelta(hours=1)
            renpy.notify("Time advanced to {}".format(gamedate.strftime('%A, %B %d, %Y %H:%M')))


    class AdvanceDate(Action): # permet d'ajouter un bouton pour changer la date, sera changé par un imagebutton
        def __call__(self):
            global gamedate
            gamedate += datetime.timedelta(days=1)
            renpy.notify("Date advanced to {}".format(gamedate.strftime('%A, %B %d, %Y %H:%M')))     

    #class addtime(action):   #avance le temps par 1mn in script,just for test, don't work
        #def __call__(self):
            #global gamedate, time_delta #original
            #gamedate += datetime.timedelta(minutes=1) #changer le chiffre pour avoir un autre delta
            #renpy.notify("Time advanced to {}".format(gamedate.strftime('%H:%M')))         

    #def addminute():  don't work

        #set_game_addminute(minute=1)
        #set_time_fields()         

    def advance_period():  #

        set_game_hour(hour=periods[store.period])
        set_time_fields()

    

    def goto_next_morning():

        set_game_hour(hour=periods[0])
        set_time_fields()


    def set_game_hour(hour):

        if hour > store.gamedate.hour:                         # changing hour to today or tomorrow?
            store.gamedate = store.gamedate.replace(hour=hour)
        else:
            store.gamedate = store.gamedate.replace(hour=hour)
            store.gamedate = store.gamedate + datetime.timedelta(days=1)


    def set_time_fields():

        if store.gamedate.hour >= periods[0] and store.gamedate.hour < periods[1]:
            store.period = 1
        elif store.gamedate.hour >= periods[1] and store.gamedate.hour < periods[2]:
            store.period = 2
        elif store.gamedate.hour >= periods[2] and store.gamedate.hour < periods[3]:
            store.period = 3
        else:
            store.period = 4

        store.hour = int(store.gamedate.hour)                   # 0 to 23
        store.minute = int(store.gamedate.minute)               # 0 to 60 ajouter le 02.04.2024 
        store.day = int(store.gamedate.day)                     # 1 to 31
        store.weekday = int(store.gamedate.weekday())           # Mon=0, Sun=6
        store.dayname = store.gamedate.strftime("%a").upper()   # MON, TUE, etc.

define periods = [8, 13, 18, 23, 8]     # The 5th time period is there to wrap around to "tomorrow".
default gamedate = datetime.datetime(2024, 1, 1, 8, 0, 0)  # start at 8am on Friday 6th March 2020. The period will be calculated based on the current hour.

default period = 0    # 1 = morning, 2 = afternoon, 3 = evening, 4 = night
default hour = 0
default day = 0
default weekday = 0
default dayname = ""
default minute = 0
Python:
# Vous pouvez placer le script de votre jeu dans ce fichier.

# Déclarez sous cette ligne les images, avec l'instruction 'image'
# ex: image eileen heureuse = "eileen_heureuse.png"




# Le jeu commence ici
label start:
     $ set_time_fields()

     m "second try to date system."

     m "i need a screen. but first i need to run the game to avoid error"
     menu:
          "run without error":
               m"all good so far"
               jump suite
          "run with errors":
               m"not good..."

     return


label suite:
# ajout d'un screen date et heure + text button for advance the date and the hour
     show screen time_screen()
     m"ajout du screen date et heure"
     menu:
          "the screen work":
               m"yes, that's good, i can add hour, date and minute with my screen "
               jump suite2
          "the screen don't work":
               m"well, that's bad"


label suite2:
# ajout
     m"now it's time to change the time by x minutes in the game."
     m"first add a fonction to change the current hour"
     m "i'm tired, too much for my poor brain with this coding, I need a good map"
     # what I need here to add time by minute (120) ???? 120 for 2 hours,  so many try for nothing...
    
     menu:
          "I can change the time, it's good":
               m"good work so far, let's try with event based in a day and hour"
          "I can't change the hour":   
               m"my bad again..."
          

              


     # later...

    #if something == True:
       # $ advance_period()
    #else:
        #$ goto_next_morning()
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,130
14,809
Why use datetime ? hummm, to have a February 29 in 2024 !!! That's my base, a full real year.
Question: What does it add as experience for the player ?

It's the question that every creator should ask himself every time he want to add a feature in his game, because it's what determine everything what will follow.

By example, in your case having correct leap years impose either the use of a more complex date system, with or without the help of datetime. This then lead to more complex triggers for the events, more time past working on the code, and it open the door for more bugs and/or code conflicts.

Every decision should always be lowered to a cost/benefit ratio.
Here, as I said, the cost is relatively high, and you witness it firsthand since it's your second question regarding this particular point. So, does the benefit worth it, does it at least equal the cost ?
I can be wrong, but from my point of view, based on my seven years of game threads reading, the answer is "no". 99% of the players will not notice that 2024 was correctly depicted as being a leap year, if even they actually take care of the date, and not just stay focused on the day of week.

After, all this doesn't mean that one cannot include features that are totally irrelevant. But he need to do it while being fully aware about the uselessness of that feature, and so to do it because it please him, what is already an acceptable benefit.
But if it's just for the rightness, then it's totally useless, especially in an adult game.
Of course, it will make the story feel more real, but it's adding reality in top of something that totally lack of reality. "Look, for the year 2024 February had 29 days as it should" will never make the player forget that the MC have a 20cm long dick, and a harem of pervert top models who pass their time exposing their DD boobs because they are all craving for sex.


If you want to experiment, last time I played it, the game Glassix was the most realistic game available on the scene. The time increment is one minute, and the girls have real time schedule that include showering, eating and even peeing.
I don't know if he kept it in the final version, but at one time he even introduced some randomness. The girl don't go peeing at the exact same hour every day, nor take the same number of minutes to perform a task.

But in the end it's something way more stressful and frustrating than enjoyable. You've to figure out each girl schedule, as well as the exact number of minutes needed for every single movement in the map. And when this is finally done, you've to plan in advance, not just your day, but your week because there's event available only once a week.
I remember that I gave up to the game precisely when he introduced the randomness. I past two days in a row missing half the girls, and mostly filling the time with the others, because the missed events were what make their story advance.
And apparently I'm not the only one to think that it was way too high in terms of realism. The game was in development for a bit less that 8 years, and it never had more ; 283 only when the last update was released. Worse, while games tend to get more support over the time, especially for a so long development period, it was the opposite for this one. The more realism was added to the game, the more it was loosing support.


what is needed for this ?
A "day since the story started" and a "period of the day" variables, nothing more is needed.

Code:
label dayHub:
    If daySinceStarted == 12:
        jump anniversary

label pnjRoomHub:
   if periodOfDay == 4:
       jump isInHisRoom
   else:
       jump isNotInHisRoom

label nap:
    $ periodOfDay += 1
Now, when I say that nothing more is needed, it's not totally true. It need a bit more, by example the code I posted above. But the spirit stay the same, you don't need more than a basic representation of the time passing to already provide a strong feeling of, well, "time passing".

What you have to keep in mind is that player want to be entertained. And this is done through the pleasure they'll have while playing, not through the realism of their experience.
Realism is what you want, not what they expect.
 
  • Like
Reactions: GNVE and darlic

Thierry29

Member
Jun 3, 2017
128
59
anne O'nymous meeeehhhhhhhh dont't kill my mood ! lol

So... why using datesystem well... I know in conjunction with import locale my datetime screen is in French !!! :cool:
If one day I create a game, I will do it in French.
for now I'm learning coding, at least I try. I don't yet have a complete scenario or the slightest image.





More seriously, my hope is perhaps too great to have a complete but simple code to follow a year.
I wanted to trigger some events with a date like:

ex: Thursday April 4> screen "oh Next week is my best friend's birthday, I have to buy him a present and/or
organize a party"
> to buy a gift and/or organize something> Then next week Thursday April 11> screen "Today it's my best friend birthday" and do the event during the day voila !


I remember reading a tutorial called "
How-To have a dynamic story that react to player choices.

"
shame on me, I don't remember the author......

dynamic story !
I think that certain events are triggered by a date like a birthday, Christmas, Valentine's Day add dynamism.

But, I do not want the boring "morning, noon, afternoon...". I take a nap, boom period change and 4h in my face... I don't like that.

1mn time delta is perhaps to much...
but if I can figure out how to add time to my code ex: take nap> add time(20) that wouldn't be bad lol

I just remembered:

I saw in the game "Jason" the author increases the time by changing with the function default gamedate (2024, 1, 1, 8, 0, 0) by $ gamedate(2024, 1, 1, 9,12, 0). and just a black screen for show this.
it could be a simple solution to test. If it works i will try it with if gamedate(2024, 3, 21, 8,0, 0).

anyway, I continue my research.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,130
14,809
anne O'nymous meeeehhhhhhhh dont't kill my mood ! lol
I've seen too many dev have it crushed after the first release of their game, seeing players totally discarding what was for them the most difficult codding part. Trust me on this, it's way better to have it crushed before this happen, than when you get "booh !" in place of the hundreds "wow" you were expecting.



So... why using datesystem well... I know in conjunction with import locale my datetime screen is in French !!! :cool:
And with _() it would be too.
Python:
screen whatever():

    text _( "This string will be open to translation." )

label whatever:
    $ renpy.notify( _( "Than one too." ) )

define whatever = _( "And even this one." )
For the date, you don't even need to works hard for the translation, the "common.rpy" file that Ren'Py would generate for the language include the strings, you just have to provide the translation.
Then this should works fine and give a translated result:
Python:
define dowStrings = [ "{#weekday}Monday", "{#weekday}Tuesday", [...] ]
define monthStrings = [ "{#month}January", "{#month}February", [...] ]

screen UI():

    hbox:
        text _( dowStrings[dayOfWeek] )
        null height 20
        text _( day )
        null height 20
        text _( monthStrings[month] )
Side note: I'm not even sure that the _() is still needed.


More seriously, my hope is perhaps too great to have a complete but simple code to follow a year.
I wanted to trigger some events with a date like:

ex: Thursday April 4> screen "oh Next week is my best friend's birthday, I have to buy him a present and/or
organize a party"
> to buy a gift and/or organize something> Then next week Thursday April 11> screen "Today it's my best friend birthday" and do the event during the day voila !
And as I said, you don't need a full system relying on datetime for this. You don't even need to know the exact date.

Like I said and shown in my second post, you can do it by having a calendar in front of your eyes and use the number of weeks and day of the week as trigger:
Python:
label whatever:
    if int( days / 7 ) == 14 and days % 7 == 4:
        menu:
            MC "Oh next week is my best friend's birthday. What should I do ?"
            "I'll throw a party for him.":
                $ party = True
                $ gift = False
            "I'll buy him something.":
                $ party = False
                $ gift = True
    elif int( days / 7 ) == 15 and days % 7 == 4:
        if party:
           MC "Time for the birthday party !"
       else:
           MC "Time to give him his gift."
What you can simplify:
Python:
init python:
    def eventDay( week, dow ):
        if not int( inGameDay / 7 ) == week:
            return False
        if not inGameDay % 7 == dow:
            return False
        return True

# The game starts the 5 February
default inGameDay = 36

label whatever:
    if eventDay( 14, 4 ):
        menu:
            MC "Oh next week is my best friend's birthday. What should I do ?"
            "I'll throw a party for him.":
                $ party = True
                $ gift = False
            "I'll buy him something.":
                $ party = False
                $ gift = True
    elif eventDay( 15, 4 ):
        if party:
           MC "Time for the birthday party !"
       else:
           MC "Time to give him his gift."
And if you want your game to take place over more than one year, it's still possible:
Python:
init python:
    def eventDay( year, week, dow ):
        if not int( inGameDay / 365 ) == year:
            return False
        if not int( inGameDay / 7 ) == week:
            return False
        if not inGameDay % 7 == dow:
            return False
        return True

# Still the 5 February, but +365 for the year to starts at 1
default inGameDay = 401

label whatever:
    if eventDay( 1, 14, 4 ):
        [...]
    elif eventDay( 1, 15, 4 ):
        [...]
    elif eventDay( 2, 14, 4 ):
       if party:
           MC "He loved last year party, let's do a party too that year."
       else:
           MC "I was cheap last year, this time I'll throw a party for him."
It would works as fine as relying on datetime. But in place of some complex code, the only thing you would need is to increment inGameDay at the end of each day, and to have kept one of the many calendar that real estate agencies left in your mailbox in December ; they generally have the week number printed, so you don't even have to add them yourself.

is always the rule. If you can do it without headache and a ton of code, then do it without headache and a ton of code.
side note: I just wish that those talking about it finally agree for a signification, because it starts to become ridiculous all those "Keep it Simple, Stupid !", "Keep it Simply Stupid" and others "Keep it Super Simple". But well, at least they all explain it the same way.


shame on me, I don't remember the author......
It's not a big lost. I know the guy, he's lazy as fuck and I don't even talk about his grumpiness :giggle:


But, I do not want the boring "morning, noon, afternoon...". I take a nap, boom period change and 4h in my face... I don't like that.
Then have 24 hours days, it's not a problem.
Periods are just a number translated into a word, you can have as many as you want. But as I said above, the closer periods are from real time, the more frustrating the game will become because the easier it will be to miss something.
Plus, if the story have optional events (by example girls that can be pursued, or not), the more there's periods, the more players who decide to not follow an optional path will have to take nap because there's nothing to do for him.


1mn time delta is perhaps to much...
It's definitively too much. And I'm tempted to say that even 1 hour delta is too much. At least for a pure free roaming approach.
But for a mixed approach, where there's forced events and free roaming, it can works. This because the forced events can be used to fill the gap.
To keep your example, the game rely on 1 hour periods, but buying the gift, or starting to organize the party, can perfectly be a scene that will take 12 hours. What would still leave 4 periods of free roaming for the player that day.


I saw in the game "Jason" [...]
I'll starts to think that perfectionism too is a french curse...
Break your chains and see the light, it can be more than "good enough" without needing to be perfect.
 

GNVE

Active Member
Jul 20, 2018
635
1,118
Just to add to the complexity, may I add my insanity to the mix? I'm not advocating for it or suggesting it is a good idea but I coded a system with two date systems.
There is a VN side and a management/simulation side. The setting is a town/college and to prevent either having a college spring up over the course of a week or a group of 50-yo still not having graduated the simulation runs at 7x speed (so a week passes for every day of VN time. (this may change later if it feels to slow or fast).
The VN side increments in minutes but events run at periods so you can cram in multiple events during the morning for instance. (e.g. breakfast with person 30 min, class 1 hour townhall celebration 2 hours).
I'm aware the code has some redundancy but eh...

Again to make it extra clear: This is insanity would not recommend.

Python:
    class timeclass:    #adding in EOD modules
        standards = {'nextday':{'Monday':'Tuesday','Tuesday':'Wednesday','Wednesday':'Thursday','Thursday':'Friday','Friday':'Saturday','Saturday':'Sunday','Sunday':'Monday'},
                    'nextmonth':{'January':'February', 'February':'March', 'March':'April', 'April':'May', 'May':'June', 'June':'July', 'July':'August', 'August':'September', 'September':'October', 'October':'November', 'November':'December', 'December':'January'},
                    'monthdays': {'January':31,'February':28,'March':31,'April':30,'May':31,'June':30,'July':31,'August':31,'September':30,'October':31,'November':30,'December':31},
                    'nextseason':{'spring':'summer', 'summer':'autumn', 'autumn':'winter', 'winter':'spring'}}

        def __init__(self, dayN=0, dateday=1, dayname='Saturday', hour=8, minute=0, period='morning', month='April', simseason='spring', vnseason='spring', simyear=0, vnyear=0):
            self.dayN = dayN
            self.dateday = dateday 
            self.dayname = dayname
            self.hour = hour
            self.minute = minute
            self.period = period
            self.month = month      #Only used for special holiday events like christmas, carnival etc
            self.simseason = simseason
            self.vnseason = vnseason
            self.simyear = simyear
            self.vnyear = vnyear


        def EOD(self):
            self.dayN += 1
            if (self.dayN + 5) % 13 == 0:
                self.simseason = self.standards['nextseason'][self.simseason]
            if (self.dayN + 14) % 52 == 0:
                self.simyear += 1
            self.dayname = self.standards['nextday'][self.dayname]
            self.dateday += 1
            if self.dateday > self.standards['monthdays'][self.month]:
                self.dateday = 1
                self.month = self.standards['nextmonth'][self.month]
                if self.month == 'January':
                    self.vnyear += 1
                for i in ['March', 'June', 'September', 'December']:
                    if self.month == i:
                        self.vnseason = self.standards['nextseason'][self.vnseason]
            
            # tourism.EOD()

            # town.EOD()
            # county.EOD()
            # state.EOD()
            # country.EOD()

            # catholic.EOD()
            # protestant.EOD()
            # nondiscript.EOD()


        def timeinc(self, newmin):
            if newmin > 0:
                self.hour += newmin // 60
                self.minute += newmin % 60

            while self.minute >= 60:
                self.minute -= 60
                self.hour += 1

            while self.hour >= 24:
                self.hour -= 24
                self.EOD()

            if self.hour < 6:
                self.period = 'night'
            elif self.hour < 12:
                self.period = 'morning'
            elif self.hour < 18:
                self.period = 'afternoon'
            else:
                self.period = 'evening'


        def displaytime(self):
            """Returns the time in a 00:00 24h format"""
            temptime = ''

            if self.hour < 10:
                temptime += '0' + str(self.hour)
            else:
                temptime += str(self.hour)
            
            if self.minute < 10:
                temptime += ':0' + str(self.minute)
            else:
                temptime += ':' + str(self.minute)
            
            return temptime
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,130
14,809
[...] I coded a system with two date systems.
What did I just said ? "Kiss is always the rule" :cry:


More seriously, as insane as it is, it's more KiSS than it looks. Deciding to go with two date systems is without doubt easier than trying to make the two pace coexist peacefully with a single system.


But one thing is important to keep in mind, both for you and OP: A program is not a carbon copy of the reality, but a copycat.

What matter is the result, not the way you achieve it. Therefore, there's no obligation to have the time divided in hours -> days -> weeks -> months.
You can perfectly decide that it will be hours -> zorglub -> tagada -> weeks -> months. With a zorglub being 14 hours, while a tagada is 4 zorglubs. Then, 3 tagadas being 168 hours, it fall back to the actual length of a week. You'll just have to come with a conversion method for when you need to express the time in hours and days ; what is easier to say than to do with my example.

What I mean, is that it must be your needs that define how your program will mimic reality, and not reality that define how your program must be coded. So, both of you needs to adapt the time to your idea, and not your idea to the time.

In your case I would probably define "curriculum" as base for the time, with it being "how long does it need to acquire a level of knowledge". Then, I would decide its length in days, let's say 42 (so 6 weeks), but only if I really need to have a day correspondence. If what day it is isn't really important, you can perfectly have it a purely arbitrary and undefined.
Then, like people do not pass 100% of their time studying, I would split days into 8 periods of 3 hours. Periods that would themselves be divided in hours to fit with the VN part.
What would lead to a time system with hours -> periods -> days -> weeks -> curriculum ; with a conversion method to display the month if you need it.

Thought more deeply, this would permit you to have only one time system, but which would operate at two different level, depending if it's the VN part or the management part.
For the VN part, it operate at hour and days level, and for the management part, at periods and curriculum level ; you define what will be studied for this "curriculum", as well has what to do for each period. By example:
  1. [0-2:59] sleep
  2. [3-5:59] sleep
  3. [6:8:59] free time
  4. [9:11:59] study
  5. [12:14:59] hangout with friend
  6. [15:17:59] study
  7. [18:20:59] free time
  8. [21:23:59] hangout with girls
With possibly a bit of "days", to not study 7 days a week, and/or to not strictly follow the same schedule every days.

It's what is taught during algorithm courses, always starts by the top, then go down level by level, until you reach the code. If you're rigorous enough while doing this, the time system should come naturally when you'll finally need it.
And this even apply in your case, because "there's a VN part and there's a management part" is the second level. The real top is "how the two of them will cohabit".


Now, it doesn't mean that your approach is wrong. It's academically wrong, but the first thing that most programmers learn once graduated is that "academically right" often mean "practically wrong".
We generally build our program like a jigsaw, starting at mid level in regard of the algorithm, then try to figure how to put the pieces together, therefore what the higher algorithms should looks like. It's bad, but we don't have the time (at works), nor the will (at home) for a full algorithmic approach.

As long as it works, you understand it, and you don't struggle, then it's the right code.
 
  • Like
Reactions: GNVE