Jump to content

2 Qs: get row # of kit in kitlist, and APPEND to every kit's CLAB


subtledoctor

Recommended Posts

Posted

My brain is turning to mush and I can't figure this stuff out, so I turn to you helpful people.

 

1) I want to find the row # of a kit in kitlist.2da. How do I do this?

 

For instance, Divine Remix has a section that checks for Ashes of Embers, and edits weapprof.2da columns for the new DR kits:

COPY_EXISTING ~weapprof.2da~ ~override~
    SET "column" = (22 + "%CDSelune%")
    FOR (row = 2; row < 35 ; row = row + 1) BEGIN
      SET_2DA_ENTRY_LATER ~aoe~ row column ~1~
    END
    SET_2DA_ENTRIES_NOW ~aoe~ 1

I can't figure out how that SET command works - %CDSelune% is being (or has been) set as a numerical value equal to its row # in kitlist.2da... but how??

 

2) I want to add APPEND some text to every kit's CLAB.2da file. I have a routine where I build an associative array from kitlist.2da, and APPEND stuff on a class-by-class basis... but here I don't need an array, because I'm not distinguishing by class. I think I just need to build a simple list of kits, and then FOR ( kit in kits ) COPY ~%kit%.2da~ ... but I've never done that and I'm not getting the formatting right.

 

Thx in advance!

Posted

For instance, Divine Remix has a section that checks for Ashes of Embers, and edits weapprof.2da columns for the new DR kits:

COPY_EXISTING ~weapprof.2da~ ~override~
    SET "column" = (22 + "%CDSelune%")
    FOR (row = 2; row < 35 ; row = row + 1) BEGIN
      SET_2DA_ENTRY_LATER ~aoe~ row column ~1~
    END
    SET_2DA_ENTRIES_NOW ~aoe~ 1
I can't figure out how that SET command works - %CDSelune% is being (or has been) set as a numerical value equal to its row # in kitlist.2da... but how??

 

It is automatically assigned when you perform ADD_KIT.

 

1) I want to find the row # of a kit in kitlist.2da. How do I do this?

If you haven't just performed an ADD_KIT, you can use READ_2DA_ENTRIES_NOW and iterate through the rows of kitlist.2da with a FOR loop. Compare the value in column 1 (ROWNAME) with the name of the kit you are looking for. When you find a row that matches, read the number from column 0.

 

2) I want to add APPEND some text to every kit's CLAB.2da file. I have a routine where I build an associative array from kitlist.2da, and APPEND stuff on a class-by-class basis... but here I don't need an array, because I'm not distinguishing by class. I think I just need to build a simple list of kits, and then FOR ( kit in kits ) COPY ~%kit%.2da~ ... but I've never done that and I'm not getting the formatting right.

Unless you already know all of the filenames, you don't want to use PHP_EACH. You'll need to go through kitlist.2da to find the CLAB files for all the kits.

Posted

Btw just to be clear, while these touch on similar things, they are in fact two completely separate issue intended for two completely separate fucntions. (Two different mods, actually.)

Unless you already know all of the filenames, you don't want to use PHP_EACH. You'll need to go through kitlist.2da to find the CLAB files for all the kits.


I don't know all the filenames. I just want to find every kit in kitlist.2da, and perform a patch on its CLAB.

I tried making a (non-associative) array with all of the kits and then running through it with ACTION_FOR_EACH, but it didn't work. My array was not being created correctly. In the end I figured this out, I just made an associative array with the kits as key1, key2, etc., and then I ran ACTION_PHP_EACH and simply ignored the result1, result2, etc. in the array. Silly, I know, but it works. :undecided:

EDIT - for posterity, here is my somewhat ridiculous code to APPEND something to the clab.2da file of every kit in the game (except for wizard kits, which I suppose I should include, but dealing with wizard kits is a different animal so I'll ignore it for now):

 

COPY_EXISTING ~clabpr01.2da~ ~override~
      ~clabdr01.2da~ ~override~
      ~clabpa01.2da~ ~override~
      ~clabrn01.2da~ ~override~
      ~clabfi01.2da~ ~override~
      ~clabth01.2da~ ~override~
   LPM remove_blank_lines
   APPEND_FILE ~mod/lib/append_text.txt~

COPY_EXISTING ~kitlist.2da~ ~override~
   COUNT_2DA_ROWS ~9~ "rows"
   FOR ( index = 1 ; index < rows ; index = index + 1 ) BEGIN
      READ_2DA_ENTRY %index% 5 9 modclab
      READ_2DA_ENTRY %index% 8 9 modclass
      DEFINE_ASSOCIATIVE_ARRAY d5_no_spells BEGIN "%modclab%" => "%modclass%" END
   END
BUT_ONLY
ACTION_PHP_EACH d5_no_spells AS poo => pu BEGIN
   ACTION_IF (FILE_EXISTS_IN_GAME ~%poo%.2da~) THEN BEGIN
      COPY_EXISTING ~%poo%.2da~ ~override~
         LPM remove_blank_lines
         APPEND_FILE ~mod/lib/append_text.txt~
      BUT_ONLY
   END
END

The %modclass% variable, and that whole half of the array, is totally useless here... except insofar as it makes for a well-formed array that I can do stuff with. If anyone can tell me how to create a nice non-associative list/array, with only the values for the %modclab% variable, then this could be simplified a bit.


If you haven't just performed an ADD_KIT, you can use READ_2DA_ENTRIES_NOW and iterate through the rows of kitlist.2da with a FOR loop. Compare the value in column 1 (ROWNAME) with the name of the kit you are looking for. When you find a row that matches, read the number from column 0.


Let's say I've set ModKit as the variable kit_name. I can find it in kitlist.2da, but my understanding is that READ_2DA_ENTRY lets you set the entry itself as a variable to use later, not the row or column. Hmm - maybe I can/must OUTER_SET the row it stops on to another variable, and then use that variable later? Like so:

COPY_EXISTING ~kitlist.2da~ ~override
   COUNT_2DA_ROWS num_rows
   FOR (row = 1; row < (num_rows - 1); row += 1) BEGIN
      READ_2DA_ENTRY row 8 9 %kit_name%
      OUTER_SET kit_row = %row%
   END
BUT_ONLY
COPY_EXISTING ~weapprof.2da~ ~override~
   COUNT_2DA_COLS num_cols
   SET "column" = (22 + "%kit_row%")
   SET_2DA_ENTRY 34 column num_cols ~3~

?? That would allow my mystery kit to get 3 points in two-weapon style...? And if I have more than one such kit, I could put them in an array and wrap all of that up inside an ACTION_PHP_EACH...? It *looks* like it might work. I guess I'll try it later when I get a chance...

 

EDIT - nope, didn't work.

Posted

      READ_2DA_ENTRY %index% 5 9 modclab
      READ_2DA_ENTRY %index% 8 9 modclass
      DEFINE_ASSOCIATIVE_ARRAY d5_no_spells BEGIN "%modclab%" => "%modclass%" END

You can use this instead:

      READ_2DA_ENTRY %index% 5 9 modclab
      SET $d5_no_spells(~%modclab%~) = 1

It's still an associative array (all of WeiDU's arrays are), but there's no need to read the class if you aren't planning on using it.

 

 

As for your second question, if you are just trying to set some values in weapprof.2da, you don't need to mess around in kitlist.2da. If you know which kit you want to modify, you can find its associated column by searching through entries in the first row. Some pseudocode:

copy weapprof.2da
  for each column
    read kit_name from row 0
    if kit_name == desired_kit
      set desired_column = column + 1
      // now I know which column has the values for the desired kit, so I can do what I want (read or set some entries)
    end
  end
If you did need to find the number assigned to a kit, here's some pseudocode for how I might do that.

copy kitlist.2da
  for each row
    read kit_name from column 1
    if kit_name == desired_kit
      read kit_number from column 0
      // now I know the kit_number for the desired kit, so I can do what I want (maybe store it for later or do something in an INNER_ACTION)
    end
  end
Posted

As for your second question, if you are just trying to set some values in weapprof.2da, you don't need to mess around in kitlist.2da. If you know which kit you want to modify,

Where this is going, is I want to be able to arbitrarily modify weaprof.2da on a class-by-class basis. Weapprof.2da has the kit labels at the top of each column, but there's no indication of which class each kit belongs to.

 

So my thought was: first, associate each kit label with its class # based on the information in kitlist.2da. Then, run the weapprof edits inside an ACTION_PHP_EACH block, which can iterate through each kit and take one action or another, based on its associated class #. As I showed above, this works great for APPENDing stuff to clab files, but I couldn't get it working with weapprof.2da.

 

I tried using the code you posted to Aquadrizzt in the third post from the top here:

http://gibberlings3.net/forums/index.php?showtopic=27382&page=2

 

That didn't work when I put it inside the ACTION_PHP_EACH block. So instead I figured I could run another check of kitlist to get the kit's row #, and use DR's trick of [weapprof_column = kitlist_row + 22]. But I only ever got that to work on the *last* kit of each class, not every one.

 

In the end I found that Rogue Rebalancing has a working example of this, and last night I was able to adapt it to my needs. Long story short, make the array from kitlist, then, instead of running [COPY_EXISTING ~weapprof.2da~] inside an [ACTION_PHP_EACH] block, run [PATCH_PHP_EACH] inside of a [COPY_EXISTING ~weapprof.2da~] block.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...