Jump to content

How can I parse a 2da file and replace text?


Recommended Posts

I'm trying to find, unsuccessfully, a way of fixing a mistake in a 2DA file with WeiDu. It's a bug that was introduced in recent versions of BGEE/BG2EE in CLSWPBON.2DA. I need to find a row for a particular class and change the penalty for a proficiency into another.

It would be easy to just replace the file entirely or do it with a programming language that I know by treating it as a text file, but I'd rather go for a non destructive solution.

Thanks

 

Edited by RoyalProtector
Link to comment

WeiDU provides several commands for manipulating tables.

This code example searches for the "SHADOWDANCER" line and changes the last column to another value.

COPY_EXISTING ~clswpbon.2da~ ~override~
  // Reads whole table into memory to speed up operation
  READ_2DA_ENTRIES_NOW clswpbon 1
  // Actual data starts at row 3
  FOR (row = 3; row < clswpbon; ++row) BEGIN
    // Reads class/kit label from column 0 for each row
    READ_2DA_ENTRY_FORMER clswpbon row 0 label
    // Match found?
    PATCH_IF (~%label%~ STR_EQ ~SHADOWDANCER~) BEGIN
      // Sets column 3 ("ZERO_SKILL_THAC0") to value 3
      // Note: It's important to put updated values into a different variable!
      SET_2DA_ENTRY_LATER clswpbon_out row 3 3
      // No need to continue the FOR-loop
      SET row = clswpbon
    END
  END
  // Write changes back to file
  SET_2DA_ENTRIES_NOW clswpbon_out 1
BUT_ONLY

 

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...