I'm not a Stellaris (or Paradox in general) modder. I am a programmer, though, and my wife does a lot of modding. I thought there might be some use in creating an extension to Stellari's Clausewitz modding script. So this is all prefacing that I don't know a ton about how Clausewitz works, I've just looked at other code and some of the docs to get the basics.
I've built the first version of that, and I'd like to ask anyone who's done modding in the past what the pain points of writing code are for you. If you have any ideas on what you'd like to see or what frustrates you about writing code, let me know.
The main goal is to produce a true extension to the language. Native Clausewitz is pushed through the compiler completely unchanged and produces a byte-identical file. I am aiming to strike a balance between features which are useful and feel like Clausewitz, without requiring people to learn a whole new language or feel like they're writing something unfamiliar.
As for what I actually have so far:
for in loops. You can specify multiple loop variables followed by a list of values for them to take on. The code inside will be duplicated with the variable values substituted in (encased in $var$ dollars), until all values have been stepped through.:= assignment operator. Syntactic sugar for set_variable = ...?=, ?>, ?>=, ?<, ?<= operators. Syntactic sugar for check_variable = ... with the appropriate comparison operators- Edit: Also added the
?!= operator, which is equivalent to NOT = { check_variable = ..., or NOT = { foo ?= bar } +=, -=, *=, /=, %= operators. Syntactic sugar for change_variable, subtract_variable, multiply_variable, divide_variable, modulo_variable.
To take an example from the Gigastructures mod, here's a modified version of the game start event found in events/giga_001_mega_events.txt:
namespace = giga_mega
####################################
### On Actions Events ##############
####################################
# On game start
event = {
id = giga_mega.001
hide_window = yes
is_triggered_only = yes
immediate = {
set_global_flag = gigastructures_enabled
set_global_flag = already_warned_about_new_megas
# math basis stuff
event_target:global_event_country = {
giga_zero := 0
giga_one := 1
}
#For crystal megabore, really
every_galaxy_planet = {
limit = {
giga_is_frozen = yes
NOT = { has_deposit_for = shipclass_research_station }
}
random = {
chance = 5
add_modifier = { modifier = giga_subsurface_ocean days = -1 }
add_deposit = d_subsurface_ocean_deposit_1
}
}
random_list = {
40 = {
modifier = {
add = 10
has_global_flag = ring_gargantuan_disabled
}
modifier = {
add = 20
has_global_flag = ring_behemoth_disabled
}
modifier = {
add = 30
has_global_flag = ring_titanic_disabled
}
}
# titanic Ring System
for = {
variable = { WEIGHT SIZE }
in = {
30 titanic
20 behemoth
10 gargantuan
}
$WEIGHT$ = {
modifier = {
subtract = $WEIGHT$
has_global_flag = ring_$SIZE$_disabled
}
if = {
limit = { NOT = { any_system = { has_star_flag = ruined_$SIZE$_ring_system } } }
random_system = {
limit = {
NOR = {
is_fe_cluster = yes
any_neighbor_system = {
is_fe_cluster = yes
}
giga_is_core_system = yes
}
}
spawn_system = { initializer = "ring_world_$SIZE$_init_01" hyperlane = no }
}
}
random_system = {
limit = { has_star_flag = ruined_$SIZE$_ring_system }
# Add extra hyperlane
random_list = {
1 = { while = { count = 1 giga_generate_hyperlane = yes } }
1 = { while = { count = 2 giga_generate_hyperlane = yes } }
}
}
}
}
}
}
}
Here I'm using a for loop, the := operator, and some variable substitutions. This is the generated code:
namespace = giga_mega
####################################
### On Actions Events ##############
####################################
# On game start
event = {
id = giga_mega.001
hide_window = yes
is_triggered_only = yes
immediate = {
set_global_flag = gigastructures_enabled
set_global_flag = already_warned_about_new_megas
# math basis stuff
event_target:global_event_country = {
set_variable = { which = giga_zero value = 0 }
set_variable = { which = giga_one value = 1 }
}
#For crystal megabore, really
every_galaxy_planet = {
limit = {
giga_is_frozen = yes
NOT = { has_deposit_for = shipclass_research_station }
}
random = {
chance = 5
add_modifier = { modifier = giga_subsurface_ocean days = -1 }
add_deposit = d_subsurface_ocean_deposit_1
}
}
random_list = {
40 = {
modifier = {
add = 10
has_global_flag = ring_gargantuan_disabled
}
modifier = {
add = 20
has_global_flag = ring_behemoth_disabled
}
modifier = {
add = 30
has_global_flag = ring_titanic_disabled
}
}
# titanic Ring System
# BEGIN FOR
# WEIGHT = 30; SIZE = titanic
30 = {
modifier = {
subtract = 30
has_global_flag = ring_titanic_disabled
}
if = {
limit = { NOT = { any_system = { has_star_flag = ruined_titanic_ring_system } } }
random_system = {
limit = {
NOR = {
is_fe_cluster = yes
any_neighbor_system = {
is_fe_cluster = yes
}
giga_is_core_system = yes
}
}
spawn_system = { initializer = "ring_world_titanic_init_01" hyperlane = no }
}
}
random_system = {
limit = { has_star_flag = ruined_titanic_ring_system }
# Add extra hyperlane
random_list = {
1 = { while = { count = 1 giga_generate_hyperlane = yes } }
1 = { while = { count = 2 giga_generate_hyperlane = yes } }
}
}
}
# WEIGHT = 20; SIZE = behemoth
20 = {
modifier = {
subtract = 20
has_global_flag = ring_behemoth_disabled
}
if = {
limit = { NOT = { any_system = { has_star_flag = ruined_behemoth_ring_system } } }
random_system = {
limit = {
NOR = {
is_fe_cluster = yes
any_neighbor_system = {
is_fe_cluster = yes
}
giga_is_core_system = yes
}
}
spawn_system = { initializer = "ring_world_behemoth_init_01" hyperlane = no }
}
}
random_system = {
limit = { has_star_flag = ruined_behemoth_ring_system }
# Add extra hyperlane
random_list = {
1 = { while = { count = 1 giga_generate_hyperlane = yes } }
1 = { while = { count = 2 giga_generate_hyperlane = yes } }
}
}
}
# WEIGHT = 10; SIZE = gargantuan
10 = {
modifier = {
subtract = 10
has_global_flag = ring_gargantuan_disabled
}
if = {
limit = { NOT = { any_system = { has_star_flag = ruined_gargantuan_ring_system } } }
random_system = {
limit = {
NOR = {
is_fe_cluster = yes
any_neighbor_system = {
is_fe_cluster = yes
}
giga_is_core_system = yes
}
}
spawn_system = { initializer = "ring_world_gargantuan_init_01" hyperlane = no }
}
}
random_system = {
limit = { has_star_flag = ruined_gargantuan_ring_system }
# Add extra hyperlane
random_list = {
1 = { while = { count = 1 giga_generate_hyperlane = yes } }
1 = { while = { count = 2 giga_generate_hyperlane = yes } }
}
}
}
# END FOR
}
}
}
The original sample from Gigastructures is 151 lines. The generated code above is 152 lines. The unrolled for loop isn't identical to the original sample, but it differs only in spacing (left padding and newlines) and added comments. The code written in my extended script is 91 lines. In addition, doing it this way means that a change to the event only requires changing the code in the for block, rather than duplicated your changes through each and every copy.
It's still an early project, but I'd love to hear other people's thoughts and ideas. If none of this is useful to you, then what would be?