Idobek, on Mar 22 2004, 04:54 AM, said:
I missed what you were doing with the "patch" variable completely.
FYI: I learned that trick years ago, programming VisualBasic in school. It even had a specialized class of variables called boolean - one bit flags that could only hold TRUE or FALSE.
Idobek, on Mar 22 2004, 04:54 AM, said:
You are doing it to save typing so you may as well save as much as possible. And you have your closing SET at the end so you don't lose it. 
Now, that is a good one... why haven't I seen it myself

. On goes my quest to reduce unnecessary redundancies. BTW: it's not only typing but also less work to do for
WeiDU - instead of 4 calculations it's only one (and if you're approaching critical mass, every little helps, just ask our Guest here

).
Idobek, on Mar 22 2004, 04:54 AM, said:
IF_EVALs are IF_EVALs, WHILEs are WHILEs and variables can be awkward. An IF_EVAL will completely ignore a WHILE loop, READs for IF_EVALs should be the first thing you do. In general READs done inside a WHILE loop will be ignored outside that loop you need to use a SET for written variables to be used elsewhere.
See, that's the kind of information I'm looking for: "DOs And DON'Ts Of
WeiDU-Coding". Anyone of the cracks here interested in writing such a tutorial?
Guest, on Mar 22 2004, 06:34 AM, said:
Apologies I never followed up on this. It's good to see you here.
Well, since my way worked for me, it wasn't on the top of my list, either. Yet, it was a good example on topic. BTW: good to see you, too, and that I connected the right "face" to your posts.
Guest, on Mar 22 2004, 06:34 AM, said:
The problem with SET_2DA_ENTRY is that every execution will re-format the entire table (the columns are all made equal to the widest entry in the array). So if you try to do both the 2DA V1.0 and first column header with SET_2DA_ENTRY, only one will work (as the last action will mess with any previous formatting actions).
That's exactly the point. To restore the header you need at least one R_T, since if you'd use two S_2_Es, the second one would mess up the first's work. I think I'm getting the hang of this...
Guest, on Mar 22 2004, 06:34 AM, said:
I also ran into a strange problem when I tried to separate the formatting commands (done with REPLACE_TEXTUALLY) from the rest of the action block (I put them all at the end of the component). It almost seemed as if WeiDU was doing the REPLACE_TEXTUALLY actions before the blocks with SET_2DA_ENTRY (even though they were the last actions in the component). All of the formatting was incorrect (the column 1 header would actually appear at column 2 with whitespace for columns 0 and 1).
Ah, now I got it. You changed the sequence of my code, complaint that it wasn't working for you and left me wondering... tsk tsk. That's not very nice, you know

.
Guest, on Mar 22 2004, 06:34 AM, said:
I never tried your formatting actions, but I suspect they would have worked perfectly here (just a style decision- I tried to find a different way because I didn't like the idea of placing "dummy" text just to delete it later).
Yet you're doing pretty much the same, just you're using S_2_E for it and place a "2DA" instead of the "dummy". I changed my code to work with S_2_E, as well. It looks like this:
COPY_EXISTING ~SAVEWIZ.2DA~ ~override/SAVEWIZ.2DA~
REPLACE_TEXTUALLY ~2DA V1.0~ ~2DA_V1.0~ // Protect header
SET_2DA_ENTRY 0 0 40 ~dummy 1~
SET "col" = 40
WHILE ("%col%" > 20) BEGIN
SET_2DA_ENTRY 1 "%col%" 41 ~8~ // Death
SET_2DA_ENTRY 2 "%col%" 41 ~3~ // Wands
SET_2DA_ENTRY 3 "%col%" 41 ~5~ // Polymorph
SET_2DA_ENTRY 4 "%col%" 41 ~7~ // Breath
SET_2DA_ENTRY 5 "%col%" 41 ~4~ // Spells
SET "col" = ("%col%" - 1)
END
SET_2DA_ENTRY 0 0 41 ~~ // Restore header
REPLACE_TEXTUALLY ~2DA_V1.0~ ~2DA V1.0~
I kept the R_T for the first line (as opposed to your two S_2_Es) since it is quite unlikely to vary... wait, strike that... if somebody else's mod already messed with it, it does vary! OK, I'm sold

.
Guest, on Mar 22 2004, 06:34 AM, said:
Also, SET_2DA_ENTRY can be used to add columns.
Well, that depends on the complexity. Sometimes you're better off using APPEND_COL:
APPEND_COL ~mxsplbrd.2da~ // Add column: 7th level spells
~x x 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 4 4 4 5 5 5 5 5 5 6 6 6 6 6 6 6~
And remove the dummy "x" in a second step (one R_T ~x~ ~~ is enough).
Guest, on Mar 22 2004, 06:34 AM, said:
SET_2DA_ENTRY does work on IDS files, so it should work on any text file at all (the only caveat here is that WeiDU will re-format the file, adding extra whitespace between columns, or after the entries if there's only one). A possible alternative to the traditional REPLACE_TEXTUALLY (you don't need to know the existing entry, and you don't have to worry about differences in whitespace).
So it might even be used on the infamous music files (tho in that case formatting would be a major pain).
Cheers Armin
PS: kudos to anyone who beared with me through this overlong construct of quotes, codes and comments