• We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

skbrewer

Sergeant
8 Badges
Oct 5, 2007
54
0
  • Crusader Kings II
  • Darkest Hour
  • Europa Universalis III Complete
  • Divine Wind
  • Heir to the Throne
  • Europa Universalis III Complete
  • Europa Universalis III Complete
  • 500k Club
I'm working on an American Elections Mod where multiple choices over the years can lead to very complex decision trees. I'm looking at using flags as a possible way to ease organization and control event flow, as opposed to just having large numbers of events being slept in event actions.

Does having a few dozen global flags slow down game performance inherently? Does it only slow things down when a search for a flag happens, and if so, is it noticeable? Can you control it by being studious about clearing flags as they're no longer needed? In short, what should be considered Best Practices in the use of event flags?

One other question. This is sheer laziness since it's probably in the docs somewhere, or I could just do a test event, but can the presence or absence of a flag be used as a trigger for an event action? Consider an election in 1948. It might need something like: Action 1: Re-elect Truman(Dem), Action 2: Elect Dewey(Rep), Action 3: Elect Thurmond (States Rights), [IF(NOT(FLAG(_WALLACE_HAS_BEEN_PRES)), Action 4: Elect Wallace (Progressives))]. Is that doable?

And does it say bad things about me that when I need pseudocode for an example I default to something that looks like LISP?
 
I'm working on an American Elections Mod where multiple choices over the years can lead to very complex decision trees. I'm looking at using flags as a possible way to ease organization and control event flow, as opposed to just having large numbers of events being slept in event actions.

Does having a few dozen global flags slow down game performance inherently? Does it only slow things down when a search for a flag happens, and if so, is it noticeable? Can you control it by being studious about clearing flags as they're no longer needed? In short, what should be considered Best Practices in the use of event flags?

One other question. This is sheer laziness since it's probably in the docs somewhere, or I could just do a test event, but can the presence or absence of a flag be used as a trigger for an event action? Consider an election in 1948. It might need something like: Action 1: Re-elect Truman(Dem), Action 2: Elect Dewey(Rep), Action 3: Elect Thurmond (States Rights), [IF(NOT(FLAG(_WALLACE_HAS_BEEN_PRES)), Action 4: Elect Wallace (Progressives))]. Is that doable?

And does it say bad things about me that when I need pseudocode for an example I default to something that looks like LISP?

Imo it would be better to base candidates on the current policy sliders of Democratic/Authoritarian, Left/Right, and Dove/Hawk

Don't know LISP (I know utterly useless Scheme), using another language isn't bad. It's more about the application and structure of your coding (efficiency).
Code:
action = {
    trigger = {
        not = { local_flag which = wallace_pres }
    }
    name = "Elect A"
    .......
}

I would personally choose something like the format below with additional triggers based on the current policies for left/right and auth/dem to avoid unrealistic complete shifts in viewpoints.

Code:
action = {
     trigger = {
            or = {
                   government = democratic
                   government = fascist
            }
     }
     name = "Elect Republican"
     command = { trigger = { not = { local_flag which = REP_CAND_A_TERM2 } } type = headofstate which = MINISTERID } # Not 2 terms, re-elect/elect
     command = { trigger = { not = { local_flag which = REP_CAND_A_TERM1 } } type = local_setflag which = REP_CAND_A_TERM1 } # Not incumbent, add t1 flag
     command = { trigger = { local_flag which = REP_CAND_A_TERM2 } } type = headofstate which = ALTMINISTERID } # 2 terms, elect/re-elect alternative
     command = { trigger = { local_flag which = REP_CAND_A_TERM2 } } type = local_setflag which = REP_CAND_B_TERM1 } # set flag for alternative
     command = { trigger = { local_flag which = REP_CAND_A_TERM1 } } type = local_setflag which = REP_CAND_A_TERM2 } # Only one term, re-elect, add t2 flag
}
action = {
     trigger = {
            or = {
                   government = democratic
                   government = communist
            }
     }
     name = "Elect Democratic"
     command = { trigger = { not = { local_flag which = DEM_CAND_A_TERM2 } } type = headofstate which = MINISTERID } # Not 2 terms, re-elect/elect
     command = { trigger = { not = { local_flag which = DEM_CAND_A_TERM1 } } type = local_setflag which = DEM_CAND_A_TERM1 } # Not incumbent, add t1 flag
     command = { trigger = { local_flag which = DEM_CAND_A_TERM2 } } type = headofstate which = ALTMINISTERID } # 2 terms, elect/re-elect alternative
     command = { trigger = { local_flag which = DEM_CAND_A_TERM2 } } type = local_setflag which = DEM_CAND_B_TERM1 } # set flag for alternative
     command = { trigger = { local_flag which = DEM_CAND_A_TERM1 } } type = local_setflag which = DEM_CAND_A_TERM2 } # Only one term, re-elect, add t2 flag
}

action = {
     trigger = {
            or = {
                   government = democratic
            }
     }
     name = "Elect Populist/Farmer"
     command = { trigger = { not = { local_flag which = POP_CAND_A_TERM2 } } type = headofstate which = MINISTERID } # Not 2 terms, re-elect/elect
     command = { trigger = { not = { local_flag which = POP_CAND_A_TERM1 } } type = local_setflag which = POP_CAND_A_TERM1 } # Not incumbent, add t1 flag
     command = { trigger = { local_flag which = POP_CAND_A_TERM2 } } type = headofstate which = ALTMINISTERID } # 2 terms, elect/re-elect alternative
     command = { trigger = { local_flag which = POP_CAND_A_TERM2 } } type = local_setflag which = POP_CAND_B_TERM1 } # set flag for alternative
     command = { trigger = { local_flag which = POP_CAND_A_TERM1 } } type = local_setflag which = POP_CAND_A_TERM2 } # Only one term, re-elect, add t2 flag
}

action = {
     trigger = {
            or = {
                   government = democratic
                   government = communist
            }
     }
     name = "Elect Communist"
     command = { trigger = { not = { local_flag which = COM_CAND_A_TERM2 } } type = headofstate which = MINISTERID } # Not 2 terms, re-elect/elect
     command = { trigger = { not = { local_flag which = COM_CAND_A_TERM1 } } type = local_setflag which = COM_CAND_A_TERM1 } # Not incumbent, add t1 flag
     command = { trigger = { local_flag which = COM_CAND_A_TERM2 } } type = headofstate which = ALTMINISTERID } # 2 terms, elect/re-elect alternative
     command = { trigger = { local_flag which = COM_CAND_A_TERM2 } } type = local_setflag which = COM_CAND_B_TERM1 } # set flag for alternative
     command = { trigger = { local_flag which = COM_CAND_A_TERM1 } } type = local_setflag which = COM_CAND_A_TERM2 } # Only one term, re-elect, add t2 flag
}

action = {
     trigger = {
            or = {
                   government = democratic
                   government = fascist
            }
     }
     name = "Elect Fascist"
     command = { trigger = { not = { local_flag which = FAS_CAND_A_TERM2 } } type = headofstate which = MINISTERID } # Not 2 terms, re-elect/elect
     command = { trigger = { not = { local_flag which = FAS_CAND_A_TERM1 } } type = local_setflag which = FAS_CAND_A_TERM1 } # Not incumbent, add t1 flag
     command = { trigger = { local_flag which = FAS_CAND_A_TERM2 } } type = headofstate which = ALTMINISTERID } # 2 terms, elect/re-elect alternative
     command = { trigger = { local_flag which = FAS_CAND_A_TERM2 } } type = local_setflag which = FAS_CAND_B_TERM1 } # set flag for alternative
     command = { trigger = { local_flag which = FAS_CAND_A_TERM1 } } type = local_setflag which = FAS_CAND_A_TERM2 } # Only one term, re-elect, add t2 flag
}
 
Last edited:
As a general rule, yes, clearing unused flags would help. Let's suppose you have 100 flags set and in a trigger you want to check if a certain flag is set. Obviously the search is faster if you have only 10 flags set. However, I doubt performance would be slowed down to a noticeable degree by this difference.
So best practices are:
1) sue local flags and not global flags if not necessary;
2) clear unused flags;

Limith already gave a good example on how to use a trigger in an action.
 
As a general rule, yes, clearing unused flags would help. Let's suppose you have 100 flags set and in a trigger you want to check if a certain flag is set. Obviously the search is faster if you have only 10 flags set. However, I doubt performance would be slowed down to a noticeable degree by this difference.
So best practices are:
1) sue local flags and not global flags if not necessary;
2) clear unused flags;

Limith already gave a good example on how to use a trigger in an action.

Performance would depend based on the implementation of the flag search function. Ex. in Java, you could use an Array (not very ideal), ArrayList, List, TreeSet, IteratedList, Hashmap, etc. Certain functions (IteratedList, TreeSet) have guaranteed low search times (ln(n) which approaches infinity at increasingly slow rates). Local flags would probably be the fastest.

clr_flag doesn't remove it from a savegame iirc, so that is unnecessary.

If we were allowed to wrap multiple commands under the same trigger for a specific command (not action), then my coding style would probably be parsed more efficiently since a command trigger check would only need to be done once if a certain subflag being true (1) results in multiple commands, but alas... something like:
Code:
command = {
    trigger = {
        X
    }
    type = {
        X
    }
    type = {
        X
    }
}

Would also love if minister modifier commands could be used in events, but no...
 
Last edited:
While we're at it, let's get conditional operators (if/else, switch, case) and key/value pairs (command = { assign _US_PRES = { Roosevelt } }). ;) Or just replace the whole event writing system with a lua or python interpreter. :ninja:

Seriously though, thanks for the examples! The flags I'm using are mostly chronologically oriented, (how many terms have certain people served, have certain people ever been elected-- not for every candidate, just for certain event chains-- and which party controls Congress), so I don't need to really worry about saves mucking things up, and it should be simple enough to clear most flags when they're not needed. I have my election "tree" worked out all from 1936-1964 now and I'm ready to start writing the event code. There are 172 events right now JUST for the presidental election logic and not including flavor events that don't directly impact the elections (FDR dies, McNary dies, Wilkie dies, such and such decides not to run again, etc.), and mostly that's unavoidable due to the desire for different pictures and event text for story immersion, but if I can shave a few here and there that are mostly the same with clever use of flags, I'll do it.