If Word Equal to

Starts an if statement where the condition compares a word from a specified offset to a specified word to see if they are equal. If the condition is true then execute the following lines of code. Otherwise skip to the end of the if statement then continue executing codes.

One endIf can be applied. If more than one needs to be applied use the End If/Else codetype.

Syntax

Gecko Code

TTXXXXXX ZZZZZZZZ

Lua Script Equivalent

[end]
if (memory.read_u32_be(addr) == 0xZZZZZZZZ) then

Parameters

TT
Codetype: Must be 20, 21, 30, or 31.
XXXXXX
Offset for address calculation.
Add 1 to apply an endIf. The added 1 will not be used in address calculation.
TT = 20:
address = ba + XXXXXX
TT = 21:
address = ba + XXXXXX + 01000000
TT = 30:
address = po + XXXXXX
TT = 31:
address = po + XXXXXX + 01000000
ZZZZZZZZ
Value to Compare against.

Examples

The following code will compare the word at address 803EFF4C against 00100000. If they are equal then the condition is true and it will write the word 00000002 at address 803EFF50. Line 3 applies an endIf.

Gecko Code

1
2
3
203EFF4C 00100000
043EFF50 00000002
E2000001 00000000

Lua Script Equivalent

1
2
3
if (memory.read_u32_be(0x803EFF4C) == 0x00100000) then
memory.write_u32_be(0x803EFF50, 0x00000002);
end

Memory View

Offset
803EFF30
803EFF40
803EFF50
0
4
8
C
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
10
00
00
00
00
00
02
00
00
00
00
00
00
00
00
00
00
00
00

Assuming ba = 80000000...
The codetype is 20 which means the address calculation is ba + 3EFF4C = 80000000 + 3EFF4C = 803EFF4C.
So if the word at address 803EFF4C is equal to 00100000, then the word 00000002 is written at address 803EFF50.

Nested If

The following code will compare the value at address 802C0028 against 000000FF. If they are equal then the condition is true and it will write the byte value 01 at address 802C0038. Next it will compare the value at address 802C002C against 00000001. If they are equal then the condition is true and it will write the byte value 02 at address 802C0038. Line 5 applies two endIf's.

Gecko Code

1
2
3
4
5
202C0028 000000FF
002C0038 00000001
202C002C 00000001
002C0038 00000002
E2000002 00000000

Lua Script Equivalent

1
2
3
4
5
6
if (memory.read_u32_be(0x802C0028) == 0x000000FF) then
memory.write_u8(0x802C0038, 0x01);
if (memory.read_u32_be(0x802C002C) == 0x00000001) then
memory.write_u8(0x802C0038, 0x02);
end
end

Memory View

Offset
802C0020
802C0030
802C0040
0
4
8
C
00
00
00
00
00
00
00
00
00
00
00
FF
00
00
00
00
00
00
00
00
00
00
00
00
01
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
Offset
802C0020
802C0030
802C0040
0
4
8
C
00
00
00
00
00
00
00
00
00
00
00
FF
00
00
00
01
00
00
00
00
00
00
00
00
02
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00

Assuming ba = 80000000...
The codetype is 20 for both which means the address calculation is ba + XXXXXX.
Line 1: ba + 2C0028 = 80000000 + 2C0028 = 802C0028.
Line 3: ba + 2C002C = 80000000 + 2C002C = 802C002C.
So if the word at address 802C0028 is equal to 000000FF, then tye byte 01 is written at address 802C0038. But then also if the word at address 802C002C is equal to 00000001, then the byte 02 is written at address 802C0038.

Note: In the case of this code if both If Codetypes are true both of the byte write codes are set to write to the same address.
Looking at the top memory view only the first If Codetype is true while the second is false. This results in address 802C0038 having value 01. Where as in the bottom memory view both the first and the second If Codetypes are true. Which results in address 802C0038 having value 02.

Applying an endIf

The following code will compare the word at address 801000D4 against 00000080. If they are equal then the condition is true and it will write the word 00000002 at address 801000E4. Line 3 is another If Codetype. However before the comparison is made it will apply an endIf. Then it will compare the word at address 801000D4 against 00000040. If they are equal then the condition is true and it will write the word 00000001 at address 801000E4. Line 5 applies an endIf.

Gecko Code

1
2
3
4
5
301000D4 00000080
141000E4 00000002
301000ED 00000040
141000FC 00000001
E2000001 00000000

Lua Script Equivalent

1
2
3
4
5
6
if (memory.read_u32_be(0x801000D4) == 0x00000080) then

memory.write_u32_be(0x801000E4, 0x00000002);

end

if (memory.read_u32_be(0x801000EC) == 0x00000040) then

memory.write_u32_be(0x801000FC, 0x00000001);

end

Memory View

Offset
801000D0
801000E0
801000F0
0
4
8
C
00
00
00
00
00
00
00
80
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
01
00
00
00
00
00
00
00
40
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
01

Assuming po = 0x80000000.
The codetype is 30 for both which means the address calculation is po + XXXXXX.
Line 1: po + 1000D4 = 80000000 + 1000D4 = 801000D4.
Line 3: po + 1000EC = 80000000 + 1000EC = 801000EC.
So if the word at address 801000D4 is equal to 00000080, then word 00000002 is written at address 801000E4. Then if the word at address 801000EC is equal to 00000040, then word 00000001 is written at address 801000FC.

Note: That on Line 3 XXXXXX = 1000ED. This means first apply the endIf then use 1000EC for address calculation. This is reflected on Lines 3 and 4 of the Lua Script Equivalent.