How do I create a calendar?

1 favourites
  • 10 posts
From the Asset Store
c3p file of my tutorial make calendar in construct 3
  • Hello Community :) I want to create a "simple" ... :D Hell yeah - how all projects start...

    I want to create a rudimental calendar app using Construct. All functionality is to save two texts per day to e.g. local storage. It would be totally ok if the calendar "only" starts in 2020 and ends in like 5 years.

    First thought, I could create each day, each month, each day as Construct groups with variables, triggering events (e.g. only show 31 days when the month currently selected has 31 days)

    if year = 2020 activate group "2020"

    if month = "Jan" activate group "Jan2020)

    and than have each day

    and each day has two variables holding the strings...

    This of course means I need to f***ing "code" every day I want to include in my calendar :D with all correct weekdays, leap years etc... of course this is nonsense.

    Do you have any suggestion? Arrays probably are not suited, right?

    What about XML? Is this my only option? Any other way to base my events on large "sheets" and be able to save the text to the individual entries?? I have not found any plugins, former forum posts etc. Sounds almost impossible for me.

    Any help would be greatly appreciated.

    Best,

    Chris

    Tagged:

  • You should definitely not hard code dates like that. There are patterns in our calendar that are not too hard to figure out since we live it out every day. So instead you should use math to compute what dates fall on which day of the week while also taking into account leap years.

    So you should just create a UI that can display the information from your computations. So there's no need to store data (in an array for example) to figure out the calendar since it's all computations. The only data you should be storing are holidays and user entered appointments.

    A quick google brought up this website: http://mathforum.org/dr.math/faq/faq.calendar.html. It seems a little juvenile at first but shows you a lot of the math required to compute what you're looking for. Maybe not everything but should be a good starting point.

  • You should only create 31 labels with text 1 to 31 and hide 31,30 or 29 according to the month in the year taking into account the leap year. If the year can be divided by 4 it is a leap year, but not if it is dividable by 100 and yet again it is if it is divisible by 400, so very simple to implement with a function taking a year as a parameter, and returning a number 1 or 0:

    * On function 'IsLeapYear'

    * Parameter 'year' (Number)

    -> Functions: Set return value (year%4) = 0 ? (year%100) = 0 ? (year%400) = 0 ? 1 : 0 : 1 : 0

    I think that, if you wait for the next stable release of C3, there is a new date plugin that will be able to tell you the week day of a given date (value 0 to 6) corresponding to mon, tue, wed...

    Get the day (0-6) of the specified date according to universal time.

    text.plugins.date.expressions.getUTCDay

    Hope that helps

  • Thanks Fib and bartalluyn for your help and quick reply!

    The math forum website was a great start.

    The function looks very promising and sums up what the math forum explained very well :)

    I saw the beta feature for time and day; it really seems to be a good time saver. Going to look further into the beta version and hope the stable one will come shortly.

    In case nobody has further tips, I will just keep you posted on progress guys :)

    Thanks again so far!

    Chris

  • Not much of an actual update but a follow-up post on the same project but a different problem :D

    construct.net/en/forum/construct-3/how-do-i-8/stop-androids-on-screen-153087

    But here is a WIP video, since I promised to keep you posted on progress :)

    (Too bad IOS does not show visual touch feedback when screen recording, scoozäy)

    hinz.design/testserver/ScirraForum/Vid1.mp4

    Preview

  • Hi bartalluyn,

    I thought I got it done with your help. But my February is still freaky :P

    Do you maybe spot the mistake?

    Most Februaries display all 31 days :D

    Something I truly not see here.

    If you are wondering how the function is used:

    Any advice would be greatly appreciated <3

    Have a great evening.

    Best,

    Chris

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Use Else for the 'is not leap year' check.

    Personnaly, I'd always set the three dates invisible on each month change, and then just make visible the ones you care about.

  • blackhornet <3 IT IS WORKING :)))

    :D I can't believe it. Makes so much sense! Thank you so so much!!

    I hope this helps others in the future.

    Have a great day!

    Chris

  • Great it's working for you!

    and, actually, the function in my first post would have done the trick according to me...

    but it's however you want to implement it of course

    * On function 'IsLeapYear'

    * Parameter 'year' (Number)

    -> Functions: Set return value (year%4) = 0 ? (year%100) = 0 ? (year%400) = 0 ? 1 : 0 : 1 : 0

  • bartalluyn thanks :)

    I guessed so, I think I was just to dumb ... I mean unexperienced to "read" your suggested code / implement it exactly how you meant it. But as said I got what you were going for and it enabled me as a kick-off in the exact right direction.

    Have a great day!

    Chris

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)