1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Help with calendar lua

Discussion in 'Civ5 - SDK / LUA' started by Mr_Wii, Oct 15, 2020.

  1. Mr_Wii

    Mr_Wii Chieftain

    Joined:
    Apr 5, 2017
    Messages:
    2
    I've tried to add a custom calendar for a scenario I'm making, but it doesn't update in-game.

    Here's the code:

    -- Creates a daily calendar to be used in place of the standard monthly/yearly ones

    -- Global table containing the calendar
    g_DailyCalendar = {};

    -- Change these variables to customize the calendar
    local iStartYear = 1848; -- Start year
    local iStartMonth = 2; -- Month, numerical (1-6)
    local iStartDay = 1; -- Day of the month (1)
    local iEndYear = 1870; -- Ends September 1

    -- Creates a calendar table containing days associated to turns
    function PopulateDailyCalendar()
    local iLeapDay = 0;
    local iTurn = 0;
    local MonthName = {"January", "March", "May", "July", "September", "November"};

    for iYear = iStartYear, iEndYear, 1 do
    if IsLeapYear(iYear) then
    iLeapDay = 1;
    else
    iLeapDay = 0;
    end

    local iYearStartDay = 1;
    local iMonth = 1;
    local iMonthDay = 1;
    local MonthLength = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
    local Month = "Month";
    local Day = 0;
    local CalendarDay = "CalendarDay";

    -- Sets the calendar to start counting at the start date
    if iTurn == 0 then
    -- Catch any errors in the start date
    if iStartMonth > 6 then
    iStartMonth = 6;
    elseif iStartMonth < 1 then
    iStartMonth = 1;
    end
    if iStartDay > MonthLength[iStartMonth] then
    iStartDay = MonthLength[iStartMonth];
    elseif iStartDay < 1 then
    iStartDay = 1;
    end

    iMonth = iStartMonth;
    iMonthDay = iStartDay;

    for i = 1, iStartMonth, 1 do
    if i > 1 then
    iYearStartDay = iYearStartDay + MonthLength[i - 1];
    end
    end
    iYearStartDay = iYearStartDay + iStartDay - 1;
    end

    for iDay = iYearStartDay, 6
    if iMonthDay < MonthLength[iMonth] then
    Day = iMonthDay;
    Month = MonthName[iMonth];
    iMonthDay = iMonthDay + 1;
    else
    Day = iMonthDay;
    Month = MonthName[iMonth];
    iMonthDay = 1;
    iMonth = iMonth + 1;
    end

    CalendarDay = Month .. " " .. Day .. ", " .. iYear;

    g_DailyCalendar[iTurn] = CalendarDay;
    --print("g_DailyCalendar[" .. iTurn .. "] = " .. g_DailyCalendar[iTurn]);
    iTurn = iTurn + 1;
    end

    end

    end

    Is there something I'm missing / wrong code? Thanks in advance
     
  2. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,538
    Location:
    Near Portsmouth, UK
    You have a function (PopulateDailyCalendar) that's never called and a "global" (g_DailyCalendar) that's never read, so why should it do anything?

    Best to attach the actual mod (see link in my sig) rather than a random snippet of code
     

Share This Page