Grammarsalad Posted September 14, 2022 Share Posted September 14, 2022 Hello. I'm trying to add a special ability to a particular row at a particular level that is specified in an ini. I have no problem getting the code to add the GA_ ability at the designated level, but it is not consistently adding the ability to the specified row. That is, it seems to add the ability to the correct line where the clab goes up to level 50, but adds the ability to the first line (the "ABILITY1" line) when the clab goes up to level 40. I don't quite have my head wrapped around FOR loops, so I am not quite sure what is the issue. Here is the relevant code: ACTION_PHP_EACH clabz AS der_clab => der_levs BEGIN ACTION_IF (%der_levs% > 0) BEGIN COPY_EXISTING ~%der_clab%.2da~ ~override~ PATCH_IF (FILE_CONTAINS_EVALUATED(~%der_clab%.2da~ ~SCRLCRFT~)) BEGIN COUNT_2DA_COLS cols READ_2DA_ENTRIES_NOW rows cols FOR (row = 0; row < rows; ++row) BEGIN FOR (col = 0; col < cols; ++col) BEGIN READ_2DA_ENTRY_FORMER rows row col ~line~ PATCH_IF (~%line%~ STRING_EQUAL_CASE ~SCRLCRFT~) BEGIN PATCH_PRINT "Row is %row% or %rows%. col is %col%. And line is %line%." SET_2DA_ENTRY_LATER ~s2el_mng~ (%row% +3) (%der_levs% - 1) GA_B_SCRIB // b_scrib SET_2DA_ENTRIES_NOW s2el_mng 1 END //Scroll line END //for END //for END BUT_ONLY END END What I am doing is beginning the line with "SCRLCRFT" (i.e. where you would normally see "ABILITYx") and my plan is to add to that particular line. As you can see, I am "adding 3" to the row num because that worked when I first tested it (but, again, just with clabs that go up to level 50). I'm not sure what I'm doing wrong... Quote Link to comment
subtledoctor Posted September 14, 2022 Share Posted September 14, 2022 Out of curiosity, why does it need to be in a particular row? Why not APPEND a whole new row? AFAIK the number of rows a CLAB table can process is functionally unlimited, and the column count doesn't even need to be consistent, so you can completely sidestep the "40 cols vs. 50 cols" problem. (I just always append rows with 50 columns.) Quote Link to comment
Grammarsalad Posted September 14, 2022 Author Share Posted September 14, 2022 (edited) 14 minutes ago, subtledoctor said: Out of curiosity, why does it need to be in a particular row? Why not APPEND a whole new row? AFAIK the number of rows a CLAB table can process is functionally unlimited, and the column count doesn't even need to be consistent, so you can completely sidestep the "40 cols vs. 50 cols" problem. (I just always append rows with 50 columns.) Well, I'm specifying the level that the char gets the ability by ini (so that the player can change it). I actually do append a new row earlier in the code(headed by "SCRLCRFT"). My original solution was to find that newly appended line (i.e. by the text SCRLCRFT) and append at that particular line. In the php above, "der_levs" is taken from the ini for the level to be applied. There is probably a better way to do it but I can't think of one atm. Any ideas? Edited September 14, 2022 by Grammarsalad Quote Link to comment
subtledoctor Posted September 14, 2022 Share Posted September 14, 2022 Ah that makes sense - append the row, then check the .ini before setting which level the GA_ should be at. In that case, try this: ACTION_PHP_EACH clabz AS der_clab => der_levs BEGIN ACTION_IF (%der_levs% > 0) BEGIN OUTER_SET patch_row = 0 COPY_EXISTING ~%der_clab%.2da~ ~override~ PATCH_IF (FILE_CONTAINS_EVALUATED(~%der_clab%.2da~ ~SCRLCRFT~)) BEGIN // COUNT_2DA_COLS cols // ** don't bother counting cols READ_2DA_ENTRIES_NOW rows 2 FOR (row = 0; row < rows; ++row) BEGIN // FOR (col = 0; col < cols; ++col) BEGIN // don't need to check every column READ_2DA_ENTRY row 0 row_title PATCH_IF (~%row_title%~ STRING_EQUAL_CASE ~SCRLCRFT~) BEGIN SET patch_row = row END END PATCH_IF (patch_row > 0) BEGIN PATCH_PRINT "Row is %row% or %rows%. col is %col%. And line is %line%." SET_2DA_ENTRY patch_row (%der_levs%) 2 ~GA_B_SCRIB~ // b_scrib END END BUT_ONLY END END Rationales: CLAB files can have crazy column counts on each row, so don't rely on it If for whatever reason the patch_row isn't identified, we don't want to use the variable value from the last iteration, so set it to 0 at the start of every PHP_EACH and set it to > 0 inside each CLAB patch, and only apply the change if it is > 0 No need for S2ELater/S2ENow if you're only doing one patch I think the %der_levs% value should line up with the level number you want it to be, since the CLAB title column is col 0 and the level 1 column is col 1. But you might need to play around with that value in the patch I haven't tested that at all so YMMV. Quote Link to comment
Grammarsalad Posted September 15, 2022 Author Share Posted September 15, 2022 7 hours ago, subtledoctor said: Ah that makes sense - append the row, then check the .ini before setting which level the GA_ should be at. In that case, try this: ACTION_PHP_EACH clabz AS der_clab => der_levs BEGIN ACTION_IF (%der_levs% > 0) BEGIN OUTER_SET patch_row = 0 COPY_EXISTING ~%der_clab%.2da~ ~override~ PATCH_IF (FILE_CONTAINS_EVALUATED(~%der_clab%.2da~ ~SCRLCRFT~)) BEGIN // COUNT_2DA_COLS cols // ** don't bother counting cols READ_2DA_ENTRIES_NOW rows 2 FOR (row = 0; row < rows; ++row) BEGIN // FOR (col = 0; col < cols; ++col) BEGIN // don't need to check every column READ_2DA_ENTRY row 0 row_title PATCH_IF (~%row_title%~ STRING_EQUAL_CASE ~SCRLCRFT~) BEGIN SET patch_row = row END END PATCH_IF (patch_row > 0) BEGIN PATCH_PRINT "Row is %row% or %rows%. col is %col%. And line is %line%." SET_2DA_ENTRY patch_row (%der_levs%) 2 ~GA_B_SCRIB~ // b_scrib END END BUT_ONLY END END Rationales: CLAB files can have crazy column counts on each row, so don't rely on it If for whatever reason the patch_row isn't identified, we don't want to use the variable value from the last iteration, so set it to 0 at the start of every PHP_EACH and set it to > 0 inside each CLAB patch, and only apply the change if it is > 0 No need for S2ELater/S2ENow if you're only doing one patch I think the %der_levs% value should line up with the level number you want it to be, since the CLAB title column is col 0 and the level 1 column is col 1. But you might need to play around with that value in the patch I haven't tested that at all so YMMV. Awesome! Thanks! I'll give it a try Quote Link to comment
Grammarsalad Posted September 15, 2022 Author Share Posted September 15, 2022 Update, it looks like it works, but I had to make a slight change. I know you said not to read the cols but it freaked out and so I just used some of the original code to make it work again. I'm going to go back and see if I can strip out what isn't necessary, but for now this works: ACTION_PHP_EACH clabz AS der_clab => der_levs BEGIN ACTION_IF (%der_levs% > 0) BEGIN OUTER_SET patch_row = 0 COPY_EXISTING ~%der_clab%.2da~ ~override~ PATCH_IF (FILE_CONTAINS_EVALUATED(~%der_clab%.2da~ ~SCRLCRFT~)) BEGIN // COUNT_2DA_COLS cols // ** don't bother counting cols READ_2DA_ENTRIES_NOW rows 2 FOR (row = 0; row < rows; ++row) BEGIN FOR (col = 0; col < cols; ++col) BEGIN READ_2DA_ENTRY_FORMER rows row col ~row_title~ PATCH_PRINT "What is %row_title%?" PATCH_IF (~%row_title%~ STRING_EQUAL_CASE ~SCRLCRFT~) BEGIN SET patch_row = row END END END PATCH_IF (patch_row > 0) BEGIN SET_2DA_ENTRY patch_row (%der_levs%) 2 ~GA_B_SCRIB~ // b_scrib END END BUT_ONLY END END Quote Link to comment
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.