Hello everyone!
We completely neglected to properly document a back-end feature in 2.1 that's been part of our internal workflow for months now. In Swedish there's a term for this kind of oversight -- being hemmablind -- and it's been causing some consternation. We dropped the ball, and it's time to pick it back up.
else now behaves more or less like it does in every other programming or scripting language ever, and comes after an if rather than being nested inside it.
If you've ever written if statements of middling-and-up complexity for Stellaris, you've likely encountered nonsensical monstrosities like this one:
Which in the new syntax would be a much sleeker, gentler monstrosity:
(Colored lines not included, they're just to show if/else relationships!)
Yes and no. 2.1.0 retains some legacy functionality so simple if/else statements in the old syntax still work, but more complex ones might start producing unintended results. We will phase out support for the old syntax over time, so update your mods now.
No. On the code side there are maintenance and stability issues with supporting legacy syntax, and on the script side having one optimal and one sub-optimal system running in parallel is likely to cause errors and confuse. The old syntax will be phased out over the next update(s) to reduce ambiguity, save for an edge case detailed below.
Funny you should ask that very specific question! Due to reasons our programmers won't fully explain but tell me are 100% legit, you will still have to nest elses inside ifs if the if is inside the effect of a switch, e.g.
Yes, so did vanilla Stellaris and I feel your pain. Updating your mod is a one-time investment, and it will greatly improve the readability and maintainability of your script in the long run!
We completely neglected to properly document a back-end feature in 2.1 that's been part of our internal workflow for months now. In Swedish there's a term for this kind of oversight -- being hemmablind -- and it's been causing some consternation. We dropped the ball, and it's time to pick it back up.
Changelog
- Added else_if for instances where an else only contains another if
- if/else_if/else syntax is now sequential rather than nested
else now behaves more or less like it does in every other programming or scripting language ever, and comes after an if rather than being nested inside it.
If you've ever written if statements of middling-and-up complexity for Stellaris, you've likely encountered nonsensical monstrosities like this one:
Which in the new syntax would be a much sleeker, gentler monstrosity:
(Colored lines not included, they're just to show if/else relationships!)
FAQ
My mod still seems to work, am I in the clear?
Yes and no. 2.1.0 retains some legacy functionality so simple if/else statements in the old syntax still work, but more complex ones might start producing unintended results. We will phase out support for the old syntax over time, so update your mods now.
Can we keep the old syntax?
No. On the code side there are maintenance and stability issues with supporting legacy syntax, and on the script side having one optimal and one sub-optimal system running in parallel is likely to cause errors and confuse. The old syntax will be phased out over the next update(s) to reduce ambiguity, save for an edge case detailed below.
What about elses inside ifs inside switches?
Funny you should ask that very specific question! Due to reasons our programmers won't fully explain but tell me are 100% legit, you will still have to nest elses inside ifs if the if is inside the effect of a switch, e.g.
Code:
switch = {
trigger = Q
a = {}
b = {}
c = {
if = {
limit = { trigger x }
effect y
else = { effect z }
}
}
}
But I have hundreds of if/else statements in my mod
Yes, so did vanilla Stellaris and I feel your pain. Updating your mod is a one-time investment, and it will greatly improve the readability and maintainability of your script in the long run!