I've been looking into the if/else compared to ? method, and I've realised I've been really stupid.
The (condition ? action : else) is not a quick hand replacement for if/else and should only be used if you want a value returned for it.
I couldn't figure when looking at the previous byte-code example I posted why Flash was pushing and popping stuff from the stack, but it's because I wasn't using the syntax correctly.
Yet more byte-code I'm afraid:
So if you need a value returning from an if/else statement then use the ? syntax, otherwise stick with the usual way of doing things.PHP Code:/*
if(score==500){
trace("true");
} else {
trace("false");
}
*/
push 'score'
getVariable
push 500
equals
not
branchIfTrue label1
push 'true'
trace
branch label2
label1:
push 'false'
trace
label2:
/*
trace (score==500 ? "true":"false");
*/
push 'score'
getVariable
push 500
equals
branchIfTrue label3
push 'false'
branch label4
label3:
push 'true'
label4:
trace
Squize.





Reply With Quote