Chapter 5.8: Debugging 303: Visualizing Your Logic
In Part 3, you learned that `printl` is your most valuable debugging tool. It's the detective's magnifying glass. But sometimes, you need more than just text in a console; you need to *see* what your script is thinking.
PCapture-Lib enhances debugging with visual tools that draw shapes and information directly into the game world.
Drawing Bounding Boxes
Is your trace failing because an entity's collision box is bigger than you thought? Is an entity not where you expect it to be? Use dev.DrawEntityBBox() to find out.
// This think function finds the closest cube to the player and draws its box.
function DebugClosestCube() {
local player = GetPlayerEx()
if (!player) return 1.0
local closestCube = entLib.FindByName("prop_weighted_cube") // Simplified for example
if (closestCube) {
// Draw the cube's bounding box in bright magenta for 0.1 seconds.
// The color is an R G B vector.
dev.DrawEntityBBox(closestCube, Vector(255, 0, 255), 0.1)
}
return 0.1
}
Running this function will show you the exact collision boundaries of the entity in real-time, instantly revealing any spatial or collision-related bugs.
Better Logging
PCapture-Lib also provides an improved logging system. Instead of just `printl`, you can use functions that automatically format your messages and color-code them by importance.
dev.info("Player score is now {}", score): For general information.dev.warning("Turret ammo is low: {}", ammo): For non-critical problems.dev.error("Player handle is null! Cannot continue."): For critical, script-breaking errors.
This makes your console output much cleaner and helps you spot important messages in a sea of text.