Calendar woes -- in need of a simple calendar [SOLVED]

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.
Message
Author
User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Calendar woes -- in need of a simple calendar [SOLVED]

#16 Post by xela »

Ah ok, bit counter intuitive, I would have went with Monday - Saturday for Art events, Sunday as a day off with separate events and to hell with the last day of every month but your way will work just as well.

If you use images for moon, day, dotw and month separately, it'll work. I am just a horrible artist so I usually try to make things pretty with code, not art. You way will work here even better.
daikiraikimi wrote: First, in the code block here, is there a reason to add the @property before each def? Just curious.
In your code, there was confusion on where to put brackets () in order to get something from the calendar. Basically if you remove property, you'll have to type this (call the method, brackets execute something):

Code: Select all

if calendar.weekday() == "Sunday":
    ...
with property:

Code: Select all

if calendar.weekday == "Sunday":
    ...
I just made sure that you can get whatever information required in the same, bracket-less way.
Like what we're doing? Support us at:
Image

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Calendar woes -- in need of a simple calendar [SOLVED]

#17 Post by noeinan »

Oh, cool, thank you. :)

And yeah, I am more of an artist than a coder, but I have taken basic programming classes before and I am trying to relearn it. ^^ My process is probably not very intuitive because I've basically looked at another game, saw the final product, and am trying to work backwards from there using the simplest code I can manage, haha. We'll see how it turns out.

In any case, thanks a ton! Do you mind terribly if I use this code in my Ren'Py framework? I will of course credit you! :D

Link here: http://lemmasoft.renai.us/forums/viewto ... 51&t=22393
Image

Image
Image

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

Re: Calendar woes -- in need of a simple calendar [SOLVED]

#18 Post by xela »

daikiraikimi wrote:Oh, cool, thank you. :)

And yeah, I am more of an artist than a coder, but I have taken basic programming classes before and I am trying to relearn it. ^^ My process is probably not very intuitive because I've basically looked at another game, saw the final product, and am trying to work backwards from there using the simplest code I can manage, haha. We'll see how it turns out.

In any case, thanks a ton! Do you mind terribly if I use this code in my Ren'Py framework? I will of course credit you! :D

Link here: http://lemmasoft.renai.us/forums/viewto ... 51&t=22393
Not at all :)
Like what we're doing? Support us at:
Image

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Calendar woes -- in need of a simple calendar [SOLVED]

#19 Post by noeinan »

Thank you! :D
Image

Image
Image

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Calendar woes -- in need of a simple calendar [SOLVED]

#20 Post by noeinan »

Arg, sorry to bother you again, but I'm spinning my wheels trying to get my images to appear. After a few hours I managed to get the code all working without errors, but when I get to the point in game where the date is supposed to show up it just says the images are undefined. (Even though I painstakingly defined each one in the beginning of my script...)

So, I was trying to use screen language instead of overlay, since overlay is outdated:

Code: Select all

##############################################################################
# Calendar Overlay
#
# Screen that shows the passage of time during weekly activities.

init:
    $ cal_moon = Position(xpos=1.0, ypos=0.35)
    $ cal_date = Position(xpose=1.0, ypose=0.0)


screen calendar_overlay:
    hbox:
        $renpy.show("cal " + calendar.moonphase)
        $renpy.show("cal " + calendar.month)
        $renpy.show("cal " + calendar.weekday)
        $renpy.show("cal " + calendar.game_day)
    
return
And here's where I call my overlay screen:

Code: Select all

label Art:
    
    $ calendar.next() #This will causes the calendar to advance by one day.
    
    show calendar_overlay
    
    $ CRE += 1
    "You go to the forest in the back of the school to draw."
    
    call check_events #check to see if any events have been triggered.
    
    if current_day < 7 and not calendar.last_day_of_the_month:
        $ current_day += 1
        jump Art
    
    hide calendar_overlay
    
    return
I have made overlapping images for each day of the week, month, and the numbers 01 through 31 so that I can display my images. Each image is defined like so:

Code: Select all

    image cal Sunday = "cal Sunday.png" #etc.

    image cal January = "cal January.png" #etc.

    image cal 1 = "cal 01.png" #etc.
And my start label has this:

Code: Select all

label start:
    
    $ _game_menu_screen = "game_menu" # This code activates the "pause menu" in screens.rpy
    $ calendar = Calendar(5, 2, 2014, 2016) # Calendar(day, month, year, first leap year (can be ignored))
I would think that logically, it should show my images (even though I haven't defined their position it should show up somewhere...) But instead says they are undefined. (At least the game runs, though.) Is there something glaringly obvious I'm missing, or have I just messed up the script...?


[EDIT]

Partially answered this problem here: http://lemmasoft.renai.us/forums/viewto ... +undefined
Apparently, the days of the month images can't start with a number. Gotta figure out some other way to do that, but still the other images should work...
Image

Image
Image

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

Re: Calendar woes -- in need of a simple calendar [SOLVED]

#21 Post by xela »

daikiraikimi wrote: So, I was trying to use screen language instead of overlay, since overlay is outdated:
That's awesome, well done!
daikiraikimi wrote: screen calendar_overlay:
hbox:
$renpy.show("cal " + calendar.moonphase)
$renpy.show("cal " + calendar.month)
$renpy.show("cal " + calendar.weekday)
$renpy.show("cal " + calendar.game_day)

return
[/code]
Might be a bad joke on my part but whoever thought you to use screen language like this should be decapitated.
daikiraikimi wrote: I have made overlapping images for each day of the week, month, and the numbers 01 through 31 so that I can display my images. Each image is defined like so:

Code: Select all

    image cal Sunday = "cal Sunday.png" #etc.

    image cal January = "cal January.png" #etc.

    image cal 1 = "cal 01.png" #etc.
You will have to position everything yourself, I'll just throw everything from top to bottom in the top right corner of the screen. You named your files poorly by the way... but there is nothing that cannot be fixed with code.

Code: Select all

screen calendar:
    python:
        if calendar.day < 10:
            day_img = "".join(["cal 0", calenday.day, ".png"])
        else:
            day_img = "".join(["cal ", calendar.day, ".png"])
        month_img = "".join(["cal ", calendar.month, ".png"])
        dotw_img = "".join(["cal ", calendar.weekday, ".png"])
    vbox:
        align(1.0, 0)
        spacing 10
        add day_img
        add month_img
        add dotw_img
Images do not have to be defined, you've wasted your time I am afraid. This should be the only code you'll require, if you just put your images in separate folders like day/week/month and had windows or whatever OS you're running batch name them 1 - 31, 1 - 7, 1 - 12, you could have saved yourself even more time.
Like what we're doing? Support us at:
Image

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Calendar woes -- in need of a simple calendar [SOLVED]

#22 Post by noeinan »

xela wrote:

Code: Select all

screen calendar_overlay:
    hbox:
        $renpy.show("cal " + calendar.moonphase)
        $renpy.show("cal " + calendar.month)
        $renpy.show("cal " + calendar.weekday)
        $renpy.show("cal " + calendar.game_day)
    
return
Might be a bad joke on my part but whoever thought you to use screen language like this should be decapitated.
Ah, well, I guess I should have expected it to be pretty awful-- I originally tried to just add the images because I did that in a different part of my code, but it didn't work. So I tried to use show, but that didn't work, so I found someone doing this and thought maybe I had to do that to get the show command to work in a screen? Hahaha... .___.
daikiraikimi wrote: I have made overlapping images for each day of the week, month, and the numbers 01 through 31 so that I can display my images. Each image is defined like so:
xela wrote:You will have to position everything yourself, I'll just throw everything from top to bottom in the top right corner of the screen. You named your files poorly by the way... but there is nothing that cannot be fixed with code.

Code: Select all

screen calendar:
    python:
        if calendar.day < 10:
            day_img = "".join(["cal 0", calenday.day, ".png"])
        else:
            day_img = "".join(["cal ", calendar.day, ".png"])
        month_img = "".join(["cal ", calendar.month, ".png"])
        dotw_img = "".join(["cal ", calendar.weekday, ".png"])
        moon_img = "".join(["cal ", calendar.moonphase, ".png"])
    vbox:
        align(1.0, 0)
        spacing 10
        add day_img
        add month_img
        add dotw_img
        add moon_img
Images do not have to be defined, you've wasted your time I am afraid. This should be the only code you'll require, if you just put your images in separate folders like day/week/month and had windows or whatever OS you're running batch name them 1 - 31, 1 - 7, 1 - 12, you could have saved yourself even more time.
I also hadn't originally defined all those images, but when I got the "image undefined" message I thought I had to. I actually originally tried to use this bit of code made by leon, which automatically defines the images for me:

Code: Select all

init python hide:
    for file in renpy.list_files():
        if file.startswith('bg') and file.endswith('.jpg'):
            name = file.replace('BG/','').replace('/', ' ').replace('.jpg','')
            renpy.image(name, Image(file))
(Well, I didn't define them at all, then I tried to use that to define them so I didn't have to type it all out.) But I've been pretty unsuccessful at using this code to define any images other than bg images for some reason. Just doesn't work.

In any case, thank you again for helping me out-- however, after deleting my image definitions and replacing my butchered code for yours I'm still getting the image undefined message?

Is there something else I need to do? I looked at other folks having undefined image issues, but wasn't able to find the same errors they had.

[EDIT]

Oh, this is interesting. When I try to show the calendar_testing screen I also get an undefined image, even though there are no images in that screen-- only text. Curious.

[EDIT]

Okay, I commented out the calendar_testing screen and then renamed a working screen to calendar_testing just to see if it would show up and it does not. Still gets image undefined. Not entirely sure what's going on, but it must be a problem somewhere else in the code...?
Image

Image
Image

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

Re: Calendar woes -- in need of a simple calendar [SOLVED]

#23 Post by xela »

daikiraikimi wrote: Okay, I commented out the calendar_testing screen and then renamed a working screen to calendar_testing just to see if it would show up and it does not. Still gets image undefined. Not entirely sure what's going on, but it must be a problem somewhere else in the code...?
If you just copy-pasted my code, that screen is called calendar, not calendar testing. Also it is not capable of producing error that you describe, you'll either get a game crash saying IOError (you gave me bad paths to your images) or you get the screen.

Try deleting bytecode files, that helps sometimes, otherwise you did something weird elsewhere in your code.
Like what we're doing? Support us at:
Image

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Calendar woes -- in need of a simple calendar [SOLVED]

#24 Post by noeinan »

Oh, no, sorry I wasn't communicating effectively.

I got the undefined image code after just copying and pasting your "calendar" script.

Because it didn't work, the only thing I could think of is maybe my variables were outputting data that didn't match my image names-- so I wanted to run the calendar test at the end of the code you posted before just in case. But it was also giving me the undefined image code.

That said, I do think something is messed up somewhere, so I'm going to start a new file, test it, then get an older version of my code and see if adding it in works.
Image

Image
Image

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Calendar woes -- in need of a simple calendar [SOLVED]

#25 Post by noeinan »

Okay, I did so and am getting this:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/calendar.rpy", line 7: expected statement.
    class Calendar(object):
                  ^

Ren'Py Version: Ren'Py 6.16.5.525
Image

Image
Image

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

Re: Calendar woes -- in need of a simple calendar [SOLVED]

#26 Post by xela »

daikiraikimi wrote:Okay, I did so and am getting this:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/calendar.rpy", line 7: expected statement.
    class Calendar(object):
                  ^

Ren'Py Version: Ren'Py 6.16.5.525

Code: Select all

init python:
    class Calendar(object):
        bla bla bla
Like what we're doing? Support us at:
Image

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Calendar woes -- in need of a simple calendar [SOLVED]

#27 Post by noeinan »

Well, that's how the code is already organized. I guess i can take out your comments and see if that works.

[Edit]

Yeah, I'm not sure. I tried deleting your comments but it didn't make a difference. The code is just this-- copied exactly from you code.

Code: Select all

##############################################################################
# Calendar
#
# Keeps track of the day, month, year, leap year, and lunar calendar.
# Thanks to xela from the lemmasoft forums!

    class Calendar(object):
        '''Provides time-related information.
        Cheers to Rudi for mooncalendar calculations.
        '''
        def __init__(self, day=1, month=1, year=1, leapyear=False):
            """
            Expects day/month/year as they are numbered in normal calender.
            If you wish to add leapyear, specify a number of the first Leap year to come.
            """
            self.day = day
            self._month = month - 1
            self.year = year
            if not leapyear:
                self.leapyear = self.year + 4
            else:   
                self.leapyear = leapyear
           
            self.daycount_from_gamestart = 0
           
            self.days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
            self.month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
                                               'August', 'September', 'October', 'November', 'December']
            self.days_count = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
           
            self.mooncycle = 29
            self.newmoonday = 1
Image

Image
Image

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Calendar woes -- in need of a simple calendar [SOLVED]

#28 Post by noeinan »

Well, it might be something in my code junking it up. In that case I'll work on it more and could start a new thread.
Image

Image
Image

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

Re: Calendar woes -- in need of a simple calendar [SOLVED]

#29 Post by xela »

I don't really get it, I am using this in the game, I've released a copy/paste code for testing and made sure that everything is working (including the leap year). Code is sound, I don't really understand how it can cause issue if you start a new project. If you want, just send the whole thing to me and I'll prolly be able to fix it in 10 mins.
Like what we're doing? Support us at:
Image

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Calendar woes -- in need of a simple calendar [SOLVED]

#30 Post by noeinan »

Alright, thanks. Here's the game folder.
Attachments
game.zip
(300.97 KiB) Downloaded 55 times
Image

Image
Image

Post Reply

Who is online

Users browsing this forum: Google [Bot]