Changes
Jump to navigation
Jump to search
m
'else' clarification
==== Description ====
Performs a comparison between a retrieved value from memory (Bank and Address), and the unsigned byte Value given in the argument list. The type of comparison used is shown in the table below. If the comparison fails, the script pointer jumps forward by the amount specified in the final argument; the starting offset for this jump is just before the jump value argument itself. This , combined with an appropriate [[FF7/Field/Script/Opcodes/10 JMPF|jump forward]], is used to implement if/else functionality in scripts, as demonstrated below.
If the content of the 'if' block following the IFUB line is longer than 0xFF, the 'else' jump argument will also need to be longer than 0xFF, and hence you should use [[FF7/Field/Script/Opcodes/15 IFUBL|IFUBL]] instead. If the value or address is larger than 0xFF, you should use the [[FF7/Field/Script/Opcodes/18 IFUW|IFUW]]/[[FF7/Field/Script/Opcodes/19 IFUWL|IFUWL]] variants. If the value you are comparing is negative, you should use the [[FF7/Field/Script/Opcodes/16 IFSW|IFSW]]/[[FF7/Field/Script/Opcodes/17 IFSWL|IFSWL]] variants.
==== Comparison Types ====
==== If/Else Example ====
In this example, if the value found is greater than 0x30, the script halts for a shorter period of time; otherwise, the script halts for a long period of time. Note how the jump forward placed before the longer WAIT (start of the required 'else' block) ensures that on completion of the 'if' block, execution of the 'else' block is avoided. It jumps forward to just before the 0x200 WAIT, which it then executes, and returns.
The 'else' block only executes if it is jumped into by the final argument of the IFUB argument list (thus avoiding the execution of the 'if' block). Once the 'else' block is executed, script execution just continues and the 0x200 WAIT and RET is executed. Since this is also executed by the 'if' block having jumped forward to skip the else block, this demonstrates that the two code paths converge. In C++ (below) this is the equivalent of the if/else block being completed.