So in this code, “thing 3” will only occur if the previous checks failed, and “thing 4” will not occur even if it would otherwise pass the check (unless “thing 3” failed)?
So, even if all the variable checks pass, only the very first check would show, correct?
Oookay. I wasn’t sure at all (neither the wiki nor the choicescript “tutorial” offer a very clear and comprehensive explanation of the functional relationship between the three).
what exactly is the difference between *elseif trees and *if trees (aside from *else covering everything else, and *if trees not needing a *goto)
(yeah, 3 years in and it’s still a bit of a headscratcher for me)
I think it has to do with structuring in coding in general. My knowledge is limited, but iirc it has to do with how it is / was used to call various situations.
Think of printed CYOA books, and how one’d flip to different pages/numbers if they’d have one item or another…
and for choicescript, I’d say it was because the story would sometimes fall through a inner-text branch due to wonky structuring.
With multiple *if, all conditions are checked and executed if their condition passes, while on *if and *elseif chains once one of the conditions meet, the entire rest of the *if*elseif*else block will be skipped.
In this case *if (var1 = true) is evaluated and since its a true condition, var1 is true text is executed, and then the *elseif below is skipped without even being checked. If you had 10 more *elseif below they wouldn’t be checked either because one of them already met its condition.
*if (var1 = true) <----- not passed
var1 is true
*elseif (var2 = true) <----- not passed
var2 is true
*elseif (var3 = true) <----- PASSED AND EXECUTED, the rest is skipped
var3 is true
*elseif (var4 = true) <----- ignored because of previous condition met
var4 is true
*elseif (var5 = true) <----- ignored because of previous condition met
var5 is true
*elseif (var6 = true) <----- ignored because of previous condition met
var6 is true
*else <----- ignored because of previous condition met
All variables are false
In this example the result would be:
var 3 is true
And that’s it, because the *elseif (var3 = true) was met first, so it will skip the 4 other *elseif and *else below it.
But if it was:
*if (var1 = true) <----- not passed
var1 is true
*if (var2 = true) <----- not passed
var2 is true
*if (var3 = true) <----- passed and executed
var3 is true
*if (var4 = true) <----- passed and executed
var4 is true
*if (var5 = true) <----- passed and executed
var5 is true
*if (var6 = true) <----- not passed
var6 is true
The result would be:
var3 is true var4 is true var5 is true
Each *if is checked individually, so if they are true they will be executed. Note how I removed the *else, as there isn’t a way to use an *else in this block (unless you chained an enormous *if condition with many or including all these variables), if I added it like this:
*if (var1 = true) <----- not passed
var1 is true
*if (var2 = true) <----- not passed
var2 is true
*if (var3 = true) <----- passed and executed
var3 is true
*if (var4 = true) <----- passed and executed
var4 is true
*if (var5 = true) <----- passed and executed
var5 is true
*if (var6 = true) <----- not passed
var6 is true
*else <----- passed and executed
All variables are false
The result would be:
var3 is true var4 is true var5 is true All variables are false
Because the *else is only working for the *if (var6 = true) condition. In the previous case of the *if/*elseif/*else the *else will only execute if none of the others are true in that block.