jentastic
April 2nd, 2021, 16:45
Hey there! I've been using the Calendar Tutorial on the forums (https://www.fantasygrounds.com/forums/showthread.php?47885-Fantasy-Grounds-Custom-Calendar-Tutorial) to create my own custom calendar for my campaign. My calendar is ultra simple — 12 months, 30 days each, 7 days per week. I hadn't ever taken the time to learn XML, but basic programming knowledge means I actually did okay.
The problem is that every month starts on "Sunday". I see that the original creator used an `.ext` to calculate the proper start day of the month, but the LUA calculations are set for a 366 day year with alternating month lengths. I've attached the calendar `.xml` and added the LUA from that tutorial and wondered if someone could walk me through how to make the changes for my calendar?
--
-- This function sets up our custom calendar calling functions.
--
function onInit()
-- Register the function to calculate the day of week for the Example 2 calendar. In the calender mod db.xml, you tell FG which function to use with the <lunardaycalc type="string">MKCustom</lunardaycalc> tag.
CalendarManager.registerLunarDayHandler("Example3", calcExample3LunarDay);
end
--
-- This function calculates the day of the week for the MKCustom calendar. the MKCustom calendar is a simple calendar where odd months have 30 days and even months have 31 days
--
function calcExample3LunarDay(nYear, nMonth, nDay)
local rYear = nYear * 366;
local rMonth = nMonth-1;
local rMonthDays = (rMonth*30)+math.floor(rMonth/2);
local rDay = (rYear + rMonthDays + nDay)%7;
if rDay == 0 then
return 7;
end
return rDay;
end
45370
The problem is that every month starts on "Sunday". I see that the original creator used an `.ext` to calculate the proper start day of the month, but the LUA calculations are set for a 366 day year with alternating month lengths. I've attached the calendar `.xml` and added the LUA from that tutorial and wondered if someone could walk me through how to make the changes for my calendar?
--
-- This function sets up our custom calendar calling functions.
--
function onInit()
-- Register the function to calculate the day of week for the Example 2 calendar. In the calender mod db.xml, you tell FG which function to use with the <lunardaycalc type="string">MKCustom</lunardaycalc> tag.
CalendarManager.registerLunarDayHandler("Example3", calcExample3LunarDay);
end
--
-- This function calculates the day of the week for the MKCustom calendar. the MKCustom calendar is a simple calendar where odd months have 30 days and even months have 31 days
--
function calcExample3LunarDay(nYear, nMonth, nDay)
local rYear = nYear * 366;
local rMonth = nMonth-1;
local rMonthDays = (rMonth*30)+math.floor(rMonth/2);
local rDay = (rYear + rMonthDays + nDay)%7;
if rDay == 0 then
return 7;
end
return rDay;
end
45370