Jump to content


Photo

Fix missing entries in 2DA files


5 replies to this topic

#1 argent77

argent77
  • Modders
  • 723 posts
  • Gender:Male

Posted 18 October 2017 - 06:23 AM

I'm trying to add missing entries to a 2DA file, so that every line contains the same number of columns.

Example:

2DA V1.0
*
        1     2     3
NAME1   VAL1  VAL2  VAL3
NAME2   VAL1
NAME3   VAL1  VAL2
NAME4   VAL1  VAL2  VAL3

should be transformed into this:

2DA V1.0
*
        1     2     3
NAME1   VAL1  VAL2  VAL3
NAME2   VAL1  *     *
NAME3   VAL1  VAL2  *
NAME4   VAL1  VAL2  VAL3

I couldn't find any WeiDU commands that allow me to add new columns or detect the actual number of entries in a given row.

 

Any ideas?



#2 Sam.

Sam.
  • Modders
  • 117 posts
  • Gender:Male
  • Location:USA

Posted 18 October 2017 - 07:43 AM

There was some discussion here:
http://forums.pocket...ic,29685.0.html
Your best bet may be to avoid any commands specifically designed to work with 2DAs and parse the files manually e.g. with RegEx yourself.
"Ok, I've just about had my FILL of riddle asking, quest assigning, insult throwing, pun hurling, hostage taking, iron mongering, smart-arsed fools, freaks, and felons that continually test my will, mettle, strength, intelligence, and most of all, patience! If you've got a straight answer ANYWHERE in that bent little head of yours, I want to hear it pretty damn quick or I'm going to take a large blunt object roughly the size of Elminster AND his hat, and stuff it lengthwise into a crevice of your being so seldom seen that even the denizens of the nine hells themselves wouldn't touch it with a twenty-foot rusty halberd! Have I MADE myself perfectly CLEAR?!"

-- to Portalbendarwinden

--------------------

Posted Image
___________Old pen and paper modules of the 70s and 80s.___________

CA Forums CA Homepage


#3 kjeron

kjeron
  • Members
  • 67 posts

Posted 18 October 2017 - 08:59 AM

COPY_EXISTING ~7EYES.2DA~ override
 COUNT_2DA_COLS cols
 READ_2DA_ENTRIES_NOW ~READ_7EYES~ 1
 FOR (i = 3; i < READ_7EYES; ++i) BEGIN  // i = first row of data
  FOR (j = 0; j < cols; ++j) BEGIN
   PATCH_IF !VARIABLE_IS_SET EVAL ~READ_7EYES_%i%_%j%~ BEGIN
    SET j = cols
    READ_2DA_ENTRY_FORMER ~READ_7EYES~ i 0 newrow
    FOR (k = 1; k < cols; ++k) BEGIN
     PATCH_IF VARIABLE_IS_SET EVAL ~READ_7EYES_%i%_%k%~ BEGIN
      READ_2DA_ENTRY_FORMER ~READ_7EYES~ i k text
      TEXT_SPRINT newrow ~%newrow% %text%~
     END ELSE BEGIN
      TEXT_SPRINT newrow ~%newrow% *~
     END
    END
    REMOVE_2DA_ROW i 1
    INSERT_2DA_ROW i 1 ~%newrow%~
   END
  END
 END
 PRETTY_PRINT_2DA
BUT_ONLY

It requires that you know how many header rows the file has, so that it can skip them, but that number should never change per file.

Use different ~READ_~ variable for every file.



#4 argent77

argent77
  • Modders
  • 723 posts
  • Gender:Male

Posted 18 October 2017 - 10:30 AM

@kjeron Your code works nicely, thanks!

The REMOVE_2DA_ROW / INSERT_2DA_ROW operation is a trick I haven't thought of. Instead I tried to extend the structure created by READ_2DA_ENTRIES_NOW directly, but SET_2DA_ENTRIES_NOW didn't catch any of these changes.

I have slightly expanded the code and put it into a function if anyone is interested:
Spoiler

Edited by argent77, 18 October 2017 - 11:19 AM.


#5 Jarno Mikkola

Jarno Mikkola

    The Imp

  • Modders
  • 6249 posts
  • Gender:Male
  • Location:The town where the dead haven't keeled over, yet. In Finland.

Posted 18 October 2017 - 12:12 PM

Any ideas?

You do know that this is completely unneeded if you only want to insert the *'s into the table ? As the second rows same symbol is the default... meaning that the file is actually filled to without there needing to be those in place. Now of course if you then need to replace sets of those with legitimate replacement values, your solution can have a valid stance, but not in the default case.
Thias can be seen for example in cases which the mx...2da file setting the default to 0 instead of something else.
Welcome to the sanity, you are free to search for the limit, it's out there, we drew it in the sand.
Here's how to install all the ... mods you ever really could want to Infinity Engine games. I removed the stable word from there as Roxanne began to add BS mods that are likely to break compatibility from the BWS.

#6 argent77

argent77
  • Modders
  • 723 posts
  • Gender:Male

Posted 18 October 2017 - 12:35 PM

 

Any ideas?

You do know that this is completely unneeded if you only want to insert the *'s into the table ? As the second rows same symbol is the default... meaning that the file is actually filled to without there needing to be those in place. Now of course if you then need to replace sets of those with legitimate replacement values, your solution can have a valid stance, but not in the default case.
Thias can be seen for example in cases which the mx...2da file setting the default to 0 instead of something else.

 


In my case it seems to be needed. I want to expand tooltip.2da to have individual names for the 4th and 5th ability of an item, which doesn't appear to work if some entries contain less columns. Besides, it improves compatibility with other mods that try to process the file. Otherwise, a COUNT_2DA_COLS followed by COUNT_2DA_ROWS would return a misleading number of rows.





Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users