"Simple Calendar Code" help?

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
MadeVeryMerry
Newbie
Posts: 12
Joined: Wed Nov 11, 2015 12:52 am
Contact:

"Simple Calendar Code" help?

#1 Post by MadeVeryMerry »

Hi - I'm brand-new to Renpy coding and have never coded with Python before in my life, so I'm probably going to ask a lot of dumb questions. Please forgive me. Instead of doing the smart thing and starting with the basics, I'm throwing myself into the ambitious end (because I despise my life, apparently).

So I'm trying to set up a calendar for my game using this calendar here. It works more or less the way I want it to, with time advancement and a day limit that triggers an ending, but I want specifically to call events on Saturdays and Sundays that differ from weekdays. I'm not exactly sure how I can set that up.

This is in my script.rpy:

Code: Select all

init python:
    def date_overlay():
        if show_date:
            ui.text(calendar.string(), xalign=0.7, size=20)
            
    
    config.overlay_functions.append(date_overlay)


    class Calendar(object):
        '''Provides time-related information based on a sequence of day names.
        Most class methods take a daycount parameter, which is assumed to be a count
        of passed days, starting with 1 for the first day.
        newmoonday is the daycount of the first new moon, e.g. 1 for the first
        day.
        Provides date based on different logic (counter).
        '''
        def __init__(self, day=1, month=1, year=1):
            self.day = day
            self.month = month
            self.year = year
            
            self.days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
            self.month_names = ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July',
                                               'August', 'September', 'October', 'November', 'December']
            self.days_count = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
            self.mooncycle = 29
            self.newmoonday = 1
            
        def string(self):
            return "(%s) - %s %d %d"%(self.weekday(), self.month_names[self.month], self.day, self.year)
            
        def next(self):
            global day
            day = day + 1
            
            self.day += 1
            if self.day > self.days_count[self.month]:
                self.month += 1
                if self.month > 12: 
                    self.month = 1
                    self.year += 1
                self.day = 1

        def weekday(self):
            '''Returns the name of the current day according to daycount.'''
            dayidx = day - 1
            daylistidx = dayidx % len(self.days)
            return self.days[daylistidx]
                   
This is the start sequence:

Code: Select all

label start:
    python:
        day = 6
        calendar = Calendar(day=20, month=10, year=2017)
        show_date = True
        
        $ gday = 0
(The gday variable keeps track of how many days the player has spent in the game, as there's an ending event on day 30.)

And this is the code that I want to figure out what day of the week it is & what events to call.

Code: Select all

label daybegin:
    $ calendar.next() # For the next day
    $ gday += 1
    "It's day %(gday)d."
    if (gday >= 30):
        jump finalday
    if day == 1:
        jump sundaymorn
    elif day == 7:
        jump saturdaymorn
    else:
        jump weekdaymorn
For this one, I recognize that I probably need to set the if/elif for day planning to another variable, and I've tried it with "weekday == "Sunday"" without any difference. I feel like the issue lies in too many "day" variables being used.

This is my first post & my first real attempt at Renpy use, so please let me know if this needs to go to another forum.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: "Simple Calendar Code" help?

#2 Post by xela »

Code: Select all

if calendar.weekday() == "Sunday":
is a good way to check it. There is a more up to date version of this floating on the forum somewhere but this should prolly work as well.
Like what we're doing? Support us at:
Image

User avatar
MadeVeryMerry
Newbie
Posts: 12
Joined: Wed Nov 11, 2015 12:52 am
Contact:

Re: "Simple Calendar Code" help?

#3 Post by MadeVeryMerry »

That did it! Thanks so much, I feel a bit silly knowing it was such a simple fix. :')

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]