Hands-On Usage
print_variables is primarily used during mod debugging. When you need to track whether a variable on a specific country, state, or character has been correctly set, you can temporarily insert it into an execution block to output all variables and temporary variables within the current scope to the log file, making it convenient for troubleshooting logic errors. After development is complete, it is typically commented out or deleted to avoid impacting performance.
# Debug: verify whether variables are correctly assigned after a certain event fires
country_event = {
id = debug.1
hidden = yes
immediate = {
print_variables = {
file = "debug_log"
text = "=== Event debug.1 fired ==="
append = yes
print_global = yes
}
}
}
Synergy
[has_active_rule](/wiki/trigger/has_active_rule): Immediately follow with print_variables after confirming a rule is active to verify whether the variable state matches expectations when the rule fires.
[clr_country_flag](/wiki/effect/clr_country_flag): Print a variable snapshot before clearing a flag to easily compare the state before and after, pinpointing flag logic errors.
[country_event](/wiki/effect/country_event): Trigger a dedicated debug event to centralize print_variables calls, making log output more organized and convenient for batch checking across multiple scopes.
[any_owned_state](/wiki/trigger/any_owned_state): When iterating through states, call print_variables in child scopes to output variable values for each state one by one, ideal for troubleshooting state-level variable synchronization issues.
Common Pitfalls
- Forgetting to remove before release:
print_variables performs file I/O each time it executes. If left in frequently-triggered effect blocks (such as daily pulses), it will severely degrade game performance. You must delete it or wrap it with an if condition block after debugging is complete.
- Mistaking
var_list as omitting all fields: The file field is mandatory; omitting it causes script errors or unexpected output locations. The var_list is what is truly optional—omitting it outputs all variables within the scope, while including it outputs only specified variables. The behavioral difference between the two is easy to confuse.