Module:AchievementSystem: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 15: Line 15:
     local formattedMsg = "ACHIEVEMENT-DEBUG: " .. message
     local formattedMsg = "ACHIEVEMENT-DEBUG: " .. message
      
      
     -- Log to MediaWiki's debug log
     -- Primary: Log to JavaScript console with structured data for better readability
    pcall(function()
        mw.logObject({
            system = "achievement",
            message = message,
            timestamp = os.date('%H:%M:%S')
        })
    end)
   
    -- Secondary: Log to MediaWiki's debug log as backup
     mw.log(formattedMsg)
     mw.log(formattedMsg)
end
-- Function to inject visible debug information into the page
local function injectVisibleDebug(data)
    if not DEBUG_MODE then return "" end
      
      
     -- Also try to log to JavaScript console if possible
     -- Convert table to JSON string
    local jsonData = ""
     pcall(function()
     pcall(function()
         mw.logObject({debug="achievement", message=formattedMsg})
         if type(data) == "table" then
            jsonData = mw.text.jsonEncode(data)
        else
            jsonData = tostring(data)
        end
     end)
     end)
   
    -- Create a hidden div with debug info that can be seen in page source and DOM
    return string.format(
        '<div class="achievement-debug" style="display:none" data-debug="achievement">%s</div>',
        jsonData
    )
end
end