Since we're on the topic of numbers now, as a regular programmer too, this is far and away one of the most infuriating things into which I've run while hacking on CK2: lack of proper numeric (or even flags, in the case of titles) variable support. It's downright terrible the things one has to do to, in the simplest and most supported case of character scope comparison (only because they're the only scopes with numeric variables at all, best I can tell) of one variable to another variable, not a literal float.
The simplest realistic example of which I can think is having,
e.g., the variable
"dejure_holdings" defined for two or more different characters. It is the [integer] count of the number of holdings that are
de facto vassal or below plus demesne titles of a given character that fall into some
de jure territory-- let's say a kingdom. The meaning of the variable is irrelevant to the point, but I like immersion. The modder wants to compare these two characters' essentially arbitrary numeric
"dejure_holdings" variables to each other and determine which is larger. This fundamental operation, variable comparison, is a prerequisite for almost any useful work that needs to deal with numbers and logic-- long before we get to needing arbitrary [integer] arithmetic even. You'd think that the following syntax would work, but it most certainly does not.
Code:
# we're in some character scope; set the variables (contrived, obviously)
set_variable = { which = dejure_holdings value = 73 }
FROM = { set_variable = { which = dejure_holdings value = 119 } }
# ... later on in same context as before (unaware of the values in the variables)
if = { limit = { check_variable = { which = dejure_holdings value = FROM } }
# greater than or equal to FROM's variable "dejure_holdings"
# ...
}
This does not work. If somebody (Meneth, please?) knows the best way to achieve an at-least-approximate numeric comparison sort of an arbitrary number of different instances of the same variable or even the simple one-to-one aforementioned comparison with a hack that doesn't require 14,000 lines of packed comparisons to literal integers-- all completely redundant combinations-- then please let me know. My hacking around at this has only resulted in frustratingly silly solutions.
From an implementation standpoint, it'd be braindead simple to implement a
check_variable = { which = "my_variable" value = <TARGET> }, as the numeric variables tagged with their name are already attached to each of those character objects in-game and are even kept statefully, beyond the scope of their utility in some cases, and serialized to savegames. Likewise,
set_variable = { which = "my_variable" value = <TARGET> } should naturally come along with that revolutionary feature. I probably shouldn't even think to ask for arithmetic commands like addition of two arbitrarily-valued variables together or multiplication (which allows us to simulate division too). But I will.
The necessity or even impossibility of hacks to try to eek arithmetic out of a pre-Babbage virtual machine are grossly inefficient (far more than the cost of an internal hash table lookup by variable name and performing a floating-point compare, which I admit is still gross for what little computation was accomplished, but it's the difference between 5 seconds and microseconds for some jobs), terribly disabling of smart functionality (
e.g., it has killed many micro-projects undertaken to improve AI behavior), and a damn shame to the rest of this neat scripting engine.
Can we have proper variable logic operations please? Could we even have arithmetic operations on those variables (existing
change_variable command with a target scope instead of a literal value would cover addition-- multiplication or division would be the only thing to require addition of new syntax and are less important)? In other words, the commands already exist and have a syntax that would naturally apply in congruence with the rest of the language. Just allow them to use target scopes. It's OK if they're only available for characters, although, like title flags (!), they would also be very useful for titles, particularly in combination with the increasingly dynamic title support.