Get x Unit by Deployment Order

Looking for a simple asm event command that gets the Nth deployed unit and returns the unit id to memory slot C. They are ordered automatically in ram so it’s just a matter of calling the getter for X deployment slot and saving it to memory slot C.

Eg. My units are deployed as ids 0x2, 0x8, and 0x4. I simply want to find the 3rd deployed unit, which would return 4 in this case.

Anyone made this already? Or anyone want to save me some time?

I overhauled a bunch of events for my hack to make them compatible with the awesome free movement asm and it’s been pretty frustrating to fix everything.

Thanks for reading.

.thumb

.macro blh to, reg
    ldr \reg, =\to
    mov lr, \reg
    .short 0xF800
.end

.equ gMemorySlots, 0x030004B8
.equ GetUnit, 0x08019430

push { lr }
ldr r0, =gMemorySlots
ldr r0, [ r0, #4 ] @ Memory slot 0x1.
blh GetUnit, r1
ldr r0, [ r0 ] @ ROM character data.
ldrb r0, [ r0, #0x04 ] @ Character ID.
ldr r1, =gMemorySlots
str r0, [ r1, #48 ] @ Memory slot 0xC.
pop { r0 }
bx r0

(Untested 1:45 AM assembly code) but this should do it.

1 Like

Thank you very much! I was just about ready to box my hack in the face yesterday when I realized I’d have to redo my unit states events. This is a helpful example of asm, too, for my slow learning. :pensive:

1 Like

Worked perfectly once I changed that line into .endm. Thanks again!

1 Like