Skip to content

Don't visit if/else blocks that have unreachable limits #280

Open

Description

@amtep

This is mostly useful for script inside scripted effects and such. If an effect has

if = {
    limit = { $COUNT$ == 1 }
    ...
}

then there is no need to validate the rest of the block if COUNT is known to not be 1. Avoiding this validation not only saves time, it can suppress some useless warnings that would never be reached anyway, for example the use of scopes that are only set by callers that do pass COUNT = 1.

Implementation: the trigger validation functions would have to return a tri-bool (yes, no, maybe) to indicate whether a trigger is known true, known false, or indeterminate (the usual case). Probably the only cases we need to evaluate for truth are comparison of literal boolean, flag, and numerical values, and comparisons involving always. The logic of NOT, AND, OR, etc then has to be applied, and finally the if/else validation has to become more robust by among other things skipping the else branch if the if branch was always true.

Question: should there be a warning about always true / always false limits that are not in macros?

Places where this logic should apply:

  • if/elseif/else
  • trigger_if/trigger_elseif/trigger_else
  • switch
  • limits in every/ordered/random lists
  • any_ lists ?

Activity

  1. changed the title [-]Don't vieit if/else blocks that have unreachable limits[/-] [+]Don't visit if/else blocks that have unreachable limits[/+] on Sep 3, 2025
  2. Karnor commented on Sep 3, 2025

    @Karnor

    Interesting question about always = yes/no.

    There are tons of instances of this trigger in vanilla and usually similar ratio in mods because it's so useful so warnings may flood ck3-tiger's output on the larger mods, however if it's possible to turn the warning off using the config files then it shouldn't be a problem and may well come in handy where it is unintentionally set.

    Also are you going to be considering the trigger_if ladder when doing the if ladder?

  3. amtep commented on Sep 3, 2025

    @amtep
    OwnerAuthor

    Yeah I wouldn't warn about always = yes/no by itself in a trigger, just if it's used to control an if or similar.

    And yeah, trigger_if can use the same logic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions