1. Hello,

    I have recently dived into the wonderful world of Lua programming. My previous knowledge is C++, C and Java (among other languages). I am currently creating a quick little function which iterates through all the events on the current day. I find if there are no user created events then this script works perfectly, but if a user event is created it seems to get stuck. To display this behavior on screen I have printed the current Event Index. It will begin well with such an index as 0 5 1 but any succeeding index's will be 0 0 0. This seems odd as the index j is iterating(i have confirmed this). Does anyone have a reasoning to this? The sample code is below; Thank you for your time.

        OpenCalendar()
        weekday, month, day, year = CalendarGetDate()
        numEvents = CalendarGetNumDayEvents(0, day)
        print(numEvents)
        for j=1,numEvents do
            index=j
            CalendarOpenEvent(0, day, index)    
    
            print(CalendarGetEventIndex())
            print(CalendarGetEventInfo())
            title, description, creator, eventType, repeatOption, maxSize, textureIndex, weekday_event, month_event, day_event, year_event, hour, minute, lockoutWeekday, lockoutMonth, lockoutDay, lockoutYear, lockoutHour, lockoutMinute, locked, autoApprove = CalendarGetEventInfo()
    
            CalendarCloseEvent()
    
        end
    
  2. Well, you're nowhere printing the index, which is j. You're printing the information from the other calendar functions. Also, if the loop gets 'stuck', then that means Lua is throwing an error. You should ensure that you have Lua errors enabled (UI Options -> Help -> Display Lua Errors). Otherwise its incredibly difficult to diagnose.

  3. I printed the index in a prior version but did not see the point of including that print in the above code. The current calendar event which is opened is being printed though using print(CalendarGetEventIndex()). I will enable the Lua errors after work tonight and let you know what occurs.

    I hace also enabled Lua errors and am not receiving any.

  4. It's incredibly likely that some of the functions you are utilising require a server query, which means they need to be done using event handling. You could add some debug information to see what is actually being called.

    Is your iteration ending? Is it happening properly for each iteration?

  5. Yes iteration does end at the appropriate time.

  6. How would I wait for an event to be fired within a Lua script? I have discovered the two following events which may be linked to the process:

     CALENDAR_OPEN_EVENT
    
     CALENDAR_ACTION_PENDING
    
  7. I have been doing to research along with reading and understand how this should work (I was thinking to linear from my experience with C and other related languages. Below is some code which only opens 1 event as a test.

     function MMORAS_Run(event)
         if event=="PLAYER_ENTERING_WORLD" then
             print ("Start of Cal Update")
             OpenCalendar()
             weekday, month, day, year = CalendarGetDate()
             local numEvents = CalendarGetNumDayEvents(0, day)
             print(numEvents)
             index=1
             CalendarOpenEvent(0, day, index)    
         elseif (event=="CALENDAR_OPEN_EVENT") then
             print(CalendarGetEventIndex())
             title, description, creator, eventType, repeatOption, maxSize, textureIndex, weekday_event, month_event, day_event, year_event, hour, minute, lockoutWeekday, lockoutMonth, lockoutDay, lockoutYear, lockoutHour, lockoutMinute, locked, autoApprove = CalendarGetEventInfo()
             CalendarCloseEvent()    
         elseif event=="CALENDAR_CLOSE_EVENT" then
             print("Close")
         else
             print("Not Appliciable")
         end
     end
    

    This does indeed print out the event but when it calls CalendarCloseEvent() we do not see a Close be printed to the screen I believe here resides my problem. Please note this is not finished code, but rather a reference.

  8. I have resolved this issue with the following code:

     local addonName, addonData = ...
    
     local weekday, month, day, year, monthOffset
     local numEvents
     local title, hour, minute, calendarType, sequenceType, eventType, texture, modStatus, inviteStatus, invitedBy, difficulty, inviteType
     local eventTypes
    
     local XCalendarFrame = CreateFrame("Frame","XCalendarFrame",UIParent)
    
     local function OnEvent(self,event,...)
         if event == "ADDON_LOADED" then
             if arg1 == addonName then
                 if not IsAddOnLoaded("Blizzard_Calendar") then
                     LoadAddOn("Blizzard_Calendar")
                 end
                 self:UnregisterEvent(event)
             end
         elseif event == "VARIABLES_LOADED" then
             weekday, month, day, year  = CalendarGetDate()
             CalendarSetAbsMonth(month,year)
             monthOffset = 0
             numEvents = CalendarGetNumDayEvents(monthOffset, day)
             eventTypes = { CalendarEventGetTypes() }
             print(weekday,month,day,monthOffset,numEvents)
    
             for eventIndex = 1, numEvents do
                 title, hour, minute, calendarType, sequenceType, eventType, texture, modStatus, inviteStatus, invitedBy, difficulty, inviteType = CalendarGetDayEvent(monthOffset, day, eventIndex)
                 print(title, hour..":"..minute, calendarType, eventTypes[eventType], invitedBy, difficulty);
             end    
         end
    
     end
    
     XCalendarFrame:SetScript("OnEvent",OnEvent)
     XCalendarFrame:RegisterEvent("ADDON_LOADED")
     XCalendarFrame:RegisterEvent("VARIABLES_LOADED")
    
  9. Great, thanks for reporting back!