Simple one to start, but I want this drilled in properly so I'm not making silly mistakes early on while coding/debugging. I just want to 100% confirm the behaviour here as I'm understanding them:
Without braces, when declaring several if statements, each one will be considered before the condition triggers. Else statements will do something else when all the if statement conditions aren't met.
ifpdistl 1024
ifp pfacing
ifhitspace
set VARIABLE 1 // Only when 1024 units near, looking at and hitting space at the same time
else
soundonce SOUND // Otherwise be a constant nuisance if the above isn't met
A visual representation of the conditions would behave as if operating from a single line:
ifpdistl 1024 ifp pfacing ifhitspace
Braces themselves are then used to segment the if statements as their own seperate checks. Else statements in this case would only check the last conditions accessible within its nested segment
ifpdistl 1024
ifp pfacing
{
ifhitspace
set VARIABLE 1 // Only when 1024 units nearby, looking at and then hitting space
else
soundonce SOUND // Make noise when pdistl 1024 and facing. Hitting space stops the sound.
}
else
spritepal 4 // Only triggers if player isn't 1024 units nearby and looking at. Hitting space not a required condition now.
So in a situation like below, each if statement would also be considered as seperate conditions without using braces here. The lowest palette swaps will override those above if that condition is met.
The
order of placement for each condition then becomes important for more precise control.
ifpdistl 1024
spritepal 4 // When pdistl 1024 while moving, the spritepal is 4.
ifp pstanding
spritepal 23 // When not moving, the spritepal is 23 regardless of pdistl, thus overriding the first check.
ifp pducking
spritepal 6
ifp pstanding
spritepal 23
ifpdistl 1024
spritepal 4 //Placing the ifpdisl segments below pstanding results in an overriding spritepal 4, regardless of a moving/not moving state while pdistl 1024
ifp pducking
spritepal 6
Typing all this out helped organise my thoughts. I'd like to believe my understanding here is correct, but thought it's worth checking to avoid causing headache once I get into coding more complex functions.