Jump to content


Scar

Member Since 08 Feb 2004
Offline Last Active May 16 2005 07:09 AM

Topics I've Started

Code sequence

21 March 2004 - 08:44 AM

Well, I've read some side comments on other topics that lead me to believe that WeiDU does not necessarily execute code in the order it was written. I'd like to evaluate what can be done safely. Let's start with a bit of example code (FYI: it corrects the Wizard saving throw table, which was supposed to get a final boost at level 21):

COPY_EXISTING ~SAVEWIZ.2DA~ ~override/SAVEWIZ.2DA~
    REPLACE_TEXTUALLY ~2DA V1.0~ ~2DA_V1.0~
    REPLACE_TEXTUALLY ~ 1 ~ ~dummy 1 ~
    SET "col" = 40
    WHILE ("%col%" > 20) BEGIN
        SET_2DA_ENTRY 1 "%col%" 41 ~8~
        SET_2DA_ENTRY 2 "%col%" 41 ~3~
        SET_2DA_ENTRY 3 "%col%" 41 ~5~
        SET_2DA_ENTRY 4 "%col%" 41 ~7~
        SET_2DA_ENTRY 5 "%col%" 41 ~4~
        SET "col" = ("%col%" - 1)
    END
    REPLACE_TEXTUALLY ~2DA_V1.0~ ~2DA V1.0~
    REPLACE_TEXTUALLY ~dummy~ ~     ~
The WHILE loop does the real work, and it's framed with a couple of R_T to protect the header formating. The whole snippet did alright for me, but when I sent it to a friend, he complained that the R_T part didn't work and the header formating was screwed up (he's at v153, while I'm still at v148 (being a Mac head, I didn't dare to compile a new version yet)). Any comments/suggestions?

Then there's these two snippets. Both yield the same result (changing the color of the Dragon Helm to something easier on the eyes) and work alright for me:

COPY_EXISTING ~helm21.itm~ ~override/helm21.itm~
    READ_SHORT 0x6A "fxoffset"
    READ_SHORT 0x70 "#fx"
    WHILE ("%#fx%" > 0) BEGIN
        READ_SHORT ("%fxoffset%" + ("%#fx%" - 1) * 0x30) "fxtype"
        READ_LONG ("%fxoffset%" + ("%#fx%" - 1) * 0x30 + 0x8) "fxpara2"
        SET "patch" = 1
        WHILE ("%fxtype%" = 7)
          AND (("%fxpara2%" = 53) OR ("%fxpara2%" = 48))
          AND "%patch%" BEGIN
            WRITE_LONG ("%fxoffset%" + ("%#fx%" - 1) * 0x30 + 0x4) 0x65
            SET "patch" = 0
        END
        SET "#fx" = ("%#fx%" - 1)
    END
The first one, above, closely follows Idobek's wonderful tutorial. Yet, there's some redundancy in there, namely four "%#fx%" - 1. So, I slightly changed it, into this:

COPY_EXISTING ~helm21.itm~ ~override/helm21.itm~
    READ_SHORT 0x6A "fxoffset"
    READ_SHORT 0x70 "#fx"
    WHILE ("%#fx%" > 0) BEGIN
        SET "patch" = 1
        SET "#fx" = ("%#fx%" - 1)
        READ_SHORT ("%fxoffset%" + "%#fx%" * 0x30) "fxtype"
        READ_LONG ("%fxoffset%" + "%#fx%" * 0x30 + 0x8) "fxpara2"
        WHILE ("%fxtype%" = 7)
          AND (("%fxpara2%" = 53) OR ("%fxpara2%" = 48))
          AND "%patch%" BEGIN
            WRITE_LONG ("%fxoffset%" + "%#fx%" * 0x30 + 0x4) 0x65
            SET "patch" = 0
        END
    END
Here I've moved the SET "#fx" = ("%#fx%" - 1) right to the beginning of the loop, so that I need to do the calculation only once. It seems to be working for me, yet the question remains: how safe is this? Can I be certain that the SET is always executed before the subsequent READ commands? Any comments/suggestions?

Cheers, Armin