Will Multiple If Codes Work Together Here?

Started by Ghirahims_Nemesis, October 22, 2012, 09:56:57 PM

Previous topic - Next topic

Ghirahims_Nemesis

Hello. I'm still a little new to making codes, and I want to make a code to modify the value at one address (using the values at another address 2 bytes before as reference) -if- the value at the address 2 bytes before it is NOT zero. But if any are zero, I want it to skip 4 bytes and do the if/then process again. I want this to be done a certain number of times. Basically a code that does this:

change po to 80123456
Set repeat 48 times to block 6
If the value at po is NOT 0000
then
set po = po+00000002
set value at po to 50
else
set po = po+00000004
execute repeat

In summary, will this work in said situation?
4A000000 80123456
60000030 00000006
2A000000 00000000
5A010000 00000002
12000000 00000032
28000000 00000000
5A010000 00000004
62000000 00000006
E0000000 80008000

If so, is there a way to shorten the code? If not, is there a way to make such a code? Thanks in advance.

note: all addresses and values mentioned are used as examples.
[spoiler]
QuoteIt won't take more than a few moments with my friend before you're charred to a satisfying crisp. And let me tell you, that will put a spring in my step!" â€" Ghirahim, The Legend of Zelda: Skyward Sword
[/spoiler]

dcx2

Off to a good start.  The whole if structure of the code handler is awkward.  For example the else is said to not work the way it is described, though you don't use an else code.

What you wrote looks more like

po = 80123456
Set repeat 48 times to block 6
if ([po] != 0)
  po += 2
  [po] = 50
  if ([po] == 0)
    po += 4
    execute repeat block 6
end all ifs, reset po/ba

Notice the indentation.  It's not exactly what you intended.  The thing you're missing is the end-ifs - the closing brace of the if statement, so to speak.

In execution, if [po] == 0, you will just fall through to the terminator and your execute repeat will not be processed.  If [po] != 0, you'll do the first part, but your second if won't be true, so you fall through to the terminator again.

You can use E2 code type to do an end-if.  Also, if codetypes (e.g. 28, 2A) also have a special property; if you add 1 to the address being tested, it will automatically apply one end-if before starting the next if.

This is more of the pattern that you want.  I won't give you everything, so that way you can try to write it yourself.

po = 80123456
Set repeat 48 times to block 6
if ([po] != 0)
  po += 2
  [po] = 50
end if
if ([po] == 0)
  po += 4
end if
execute repeat block 6
end all ifs, reset po/ba

Ghirahims_Nemesis

Thank you! My code was successful. It had to go like this:

4A000000 80123456
60000030 00000006
2A000000 00000000
5A010000 00000002
12000000 00000032
5A010000 00000002 // Forgot to increment again to make it 4 bytes after 80123456
E2000001 00000000 // At first, I made it clear po/ba, which I lol'ed at
28000000 00000000
5A010000 00000004
E2000001 00000000 // same here
62000000 00000006
E0000000 80008000
[spoiler]
QuoteIt won't take more than a few moments with my friend before you're charred to a satisfying crisp. And let me tell you, that will put a spring in my step!" â€" Ghirahim, The Legend of Zelda: Skyward Sword
[/spoiler]

dcx2

#3
You can optimize that a bit, actually.

4A000000 80123456
60000030 00000006
2A000000 00000000 # if [po] == 0
12000002 00000032 # [po+2] = 50
E2000001 00000000 # endif
5A010000 00000004 # po += 4
62000000 00000006
E0000000 80008000