Major script debugging improvement suggestion (would love to see it released as soon as CKII's India patch):
A new scope-free, argument-free debugging effect called
assert (mirrors standard
assert programming paradigm)
Advantages:
- Extremely simple
+ No state
+ No arguments
+ No scopes
+ No effect upon game state
+ No new scripting engine computation that isn't already done
de jure
- Will save thousands of scripter troubleshooting hours quickly
- Adapts widely-used assertion programming paradigm to Paradox script cleanly (see: C/C++
assert)
- Provides first/only way to affect error.log (or a separate log file, if preferred) via a runtime script trigger
- Will improve code quality of mods / DLC content
- Will enable new scripters to learn all triggers and their usage much faster
Disadvantages:
- None
Optional increased complexity (features):
- Skip executing all
assert effects if CKII's -debugscripts command-line option was not specified, largely in order to to avoid coding a safeguard against infinite loops writing to error.log but also to maintain zero execution overhead while running normally
- Custom error messages
How it works:
As an effect (not intended for any usage as part of a trigger), it basically acts like
hidden_tooltip-- just without the tooltip snazz and instead, whenever its encapsulated trigger evaluates to false upon execution, it appends a standard "runtime script assert failed:
<filename>: line
<number>" message to error.log.
Context:
- Anywhere an effect is valid
- An enclosing character scope is demonstrated here, but like
hidden_tooltip, it should work seamlessly through any scope type.
Contrived example code:
Code:
assert = {
is_adult = no
has_character_flag = standard_education
OR = {
is_female = no
NOT = { religion_group = muslim }
}
}
Or, simply:
If the trigger within
assert evaluates false, then the aforementioned standardized error message with a filename and line number is appended to error.log. If the trigger within the
assert evaluates true,
assert does nothing at all.
This seems the most natural, most simple implementation, although you might prefer the [slightly] more verbose syntax below (mirroring the way
if works as an effect with
limit encapsulating its trigger), which could also optionally work a little like
custom_tooltip and provide a human-readable error message:
Code:
assert = {
limit = {
NOT = { has_global_flag = startup_complete }
}
text = "mod ABC: scenario XYZ: game startup completed before scenario initialized"
}
Obviously, you get the idea.
If custom error messages were provided, supporting optional use of localisation keys (with standard
custom_tooltip-style embedded variable/command substitution support) for them would obviously be the penultimate in troubleshooting utility, but such features are by no means necessary to reap the first 95% of benefit that a simple, line-numbers-only
assert would provide over the current, extraordinarily poor script debugging status quo.
Personally, this would save me a ton of hours and start being used right away in my public modding. The coder of this scripting extension would certainly reap remarkably good code karma, and it'd go a long way toward Paradox's recently-stated modding support goals (better debugging) with what I'd guess to only be an afternoon of light work for the right developer.