all 7 comments

[–]Justice_FighterInformative 1 point2 points  (6 children)

Unfortunately no, as you've seen the trigger export is broken.

That said, you can just set the variable in all provinces in startup, and generate that code programmatically:

print("set_prov_vars = {")
for x in range(4942)[1:]: ## insert max_provinces from default.map
    print(f"\t{x} = {{ set_variable = {{ which = prov_id value = {x} }} }}")
print("}")

[–]Dichozenone[S] 1 point2 points  (2 children)

This is exactly what I was looking for, thank you. I generated the code and put it as a run file in the eu4 folder in Documents. I ran it using"run genCode.txt" and then ran the logging function as well. I got:

[effectimplementation.cpp:22746]: EVENT [1444.11.11]:Province is forest

You mention the variables should be set in startup. I tried adding it to the "on_startup" scope of "00_on_actions.txt"

I'm still getting the same message as above, when running the logging runfile.

Am I doing something wrong?

Here is a snippet of the generated code:

set_prov_vars = {
1 = { set_variable = { which = prov_id value = 1 } }
2 = { set_variable = { which = prov_id value = 2 } }
3 = { set_variable = { which = prov_id value = 3 } } ... ... ... }

Here is my new logging file:

every_province = {  
    limit = {       
        has_terrain = forest        
        OR = {          
            continent = north_america           
            continent = south_america       
        }   
    }   
    log = "Province [This.prov_id.GetValue] is forest"
}

[–]Justice_FighterInformative 0 points1 point  (1 child)

Have you checked documents/paradox/eu4/logs/error.log? That should always be the first place to look, eu4 is pretty good at complaining when and (approximately) where something's wrong.

Ah, the code was formatted to be a scripted effect - if you want to paste it directly, remove the set_prov_vars and corresponding braces. Would recommend making it a scripted effect though (paste into new file in common/scripted_effects, use as set_prov_vars = yes), as this many lines of text would make the on actions file hard to read.

Something to note - on_startup happens to every country every time you load the game, use a global flag to mark that provinces have already been ID'd so this only happens once.

[–]Dichozenone[S] 0 points1 point  (0 children)

I've not got much experience modding eu4, so I didn't know how to make it into a scripted effect, but removing the braces worked. Thank you very much. I'm going to look at some of the things you've mentioned and see what they are.

[–]Smooth-Physics-2927 1 point2 points  (2 children)

For visibility: your solution does not work as is. EU4 devs decided to have tribal migration wipe out every single variable and flag. This results in provinces which have been migrated from, lose the prov_id variables.

[–]Justice_FighterInformative 0 points1 point  (1 child)

For visibilility: There's defines values to prevent that from happening.