================================================================================
                    COH3 SCARTOOLKIT - DEBUG GUIDE
================================================================================

OVERVIEW
--------
The Debug button runs your code and shows Debug_Log output in a full-screen overlay.
Your code runs first, then the results are displayed.


QUICK START
-----------
1. Attach to game (Game Search tab)
2. Go to IDE tab
3. Write your script using Debug_Log()
4. Click "Debug" button
5. See output in the full-screen overlay
6. Click "Hide" to close overlay


DEBUG FUNCTIONS
---------------

  Debug_Log(message)    - Print a message (collected and shown after code runs)
  Debug_Clear()         - Clear previous messages before adding new ones


EXAMPLE: Simple test
--------------------

Debug_Clear()
Debug_Log("Hello")
Debug_Log("Working!")


EXAMPLE: Check if functions exist
---------------------------------

Debug_Clear()
Debug_Log("=== FUNCTION CHECK ===")

local function check(name)
    local exists = type(_G[name]) == "function"
    Debug_Log(name .. ": " .. (exists and "YES" or "NO"))
end

check("AI_LockSquad")
check("AI_UnlockSquad")
check("Squad_IsValid")
check("Player_GetSquads")

Debug_Log("=== DONE ===")


EXAMPLE: Test squad lock
------------------------

Debug_Clear()
Debug_Log("=== SQUAD LOCK TEST ===")

local player = Game_GetLocalPlayer()
if not player then
    Debug_Log("ERROR: No player")
else
    Debug_Log("Player: " .. tostring(player))

    local squads = Player_GetSquads(player)
    local count = SGroup_CountSpawned(squads) or 0
    Debug_Log("Squad count: " .. count)

    if count > 0 then
        local squad = SGroup_GetSpawnedSquadAt(squads, 1)
        Debug_Log("Squad: " .. tostring(squad))

        local ok, err = pcall(function()
            AI_LockSquad(player, squad)
        end)
        Debug_Log(ok and "AI_LockSquad: SUCCESS" or ("ERROR: " .. tostring(err)))
    else
        Debug_Log("Build some units first!")
    end
end

Debug_Log("=== DONE ===")


EXAMPLE: Check resources
------------------------

Debug_Clear()

local player = Game_GetLocalPlayer()
Debug_Log("Player: " .. tostring(player))

local mp = Player_GetResource(player, RT_Manpower)
Debug_Log("Manpower: " .. tostring(mp))

local mu = Player_GetResource(player, RT_Munition)
Debug_Log("Munition: " .. tostring(mu))

local fu = Player_GetResource(player, RT_Fuel)
Debug_Log("Fuel: " .. tostring(fu))


EXAMPLE: Safe function call
---------------------------

Debug_Clear()

local ok, err = pcall(function()
    local player = Game_GetLocalPlayer()
    AI_Enable(player, true)
end)

Debug_Log(ok and "Success!" or ("Error: " .. tostring(err)))


TIPS
----
- Always use Debug_Clear() at start to clear old output
- Use pcall() for functions that might error
- Build units in-game before testing squad functions
- Output is collected then displayed (not live updating)


================================================================================
