I'd like to use the 2DA batch functions READ_2DA_ENTRIES_NOW/READ_2DA_ENTRY_FORMER and SET_2DA_ENTRIES_NOW/SET_2DA_ENTRY_LATER (which are hopefully faster), but I'm not very experienced with them. A first test didn't result into any changes. Any idea how to use these functions properly?

Edited by argent77, 20 May 2017 - 04:25 AM.

Imagination is more important than knowledge. Knowledge is limited; imagination encircles the world. - Albert Einstein

Thanks. I tried it out, but the code triggered the following error:[/code]Which is strange since the file in question has only 1333 matching lines (line 0 .. 1332). I'll test some more. (Too bad that these commands are so badly documented in the WeiDU docs.)

I tested it before posting. Did you use different string-variable for read and set, that error usually comes up when I forget and use the same string for both.READ_2DA_ENTRIES_NOW ~prefix_read_enginest~ ...READ_2DA_ENTRY_FORMER ~prefix_read_enginest~ ...SET_2DA_ENTRY_LATER ~prefix_set_enginest~ ...SET_2DA_ENTRIES_NOW ~prefix_set_enginest~ ...

That's it, thank you! I was using the same variable for read and set operations. It works now as expected. Moreover, processing time has been reduced significantly. Using READ_2DA_ENTRY/SET_2DA_ENTRY took about two seconds to finish while the *_FORMER/*_LATER variants take only a few milliseconds.

Btw, I've noticed a minor difference between the two methods. The first method appears to preserve line breaks while the second method converts everything into unix-style line breaks.

Imagination is more important than knowledge. Knowledge is limited; imagination encircles the world. - Albert Einstein

(Too bad that these commands are so badly documented in the WeiDU docs.)

What parts are unclear? I don't personally like the documentation-by-tutorial approach that is employed in this case, but I guess others do?

Using the same prefix name for READ and SET causes an error like this because reading uses its prefix for one thing and writing uses its prefix for something fundamentally different. The details of the implementations allow you to use SET_2DA_ENTRY_LATER/NOW without needing to first read the contents of the file.

Essentially, SET_2DA_ENTRY_LATER queues up changes to be written to file and SET_2DA_ENTRIES_NOW reads the file, makes the queued changes and returns. By comparison, SET_2DA_ENTRY reads the file, makes a single change and returns every time you call it. READ_2DA_ENTRIES_NOW kind of works in reverse, in that it reads the file in one swoop and stores it in memory. READ_2DA_ENTRY reads the whole file for every 2DA entry it looks up. (Technically, it does not quite work like this, because the actual file is read and written by COPY and the patches just deal in buffers (strings); the overhead you save is mostly "parsing" the 2DA string into discrete values and reconstituting it into a buffer.)

Btw, I've noticed a minor difference between the two methods. The first method appears to preserve line breaks while the second method converts everything into unix-style line breaks.

Not quite. They both rewrite the contents of the file, but SET_2DA_ENTRY rewrites it with CRLF newlines and SET_2DA_ENTRIES_NOW uses LF.

(Too bad that these commands are so badly documented in the WeiDU docs.)

What parts are unclear? I don't personally like the documentation-by-tutorial approach that is employed in this case, but I guess others do?

I would like to see a short description of the required parameters in the syntax table. Currently each command is merely referring to a tutorial.

The tutorials themselves are structured somewhat complicated. They are first using several code examples without proper explanation while the commands themselves are described more formally only further below. Moreover, I think the choice of variable names with the unusual prefix "_#_#_#" gives the false impression that it might be a formatting code or could be otherwise relevant to the SET_2DA_* / READ_2DA_* commands.

The tutorials are also using full name (e.g. READ_2DA_ENTRIES_NOW) and an alternate name (e.g. R_2_E_N) interchangeably. It would be more readable to stick to a single naming convention and mention the alternate version in the formal description part. (Is the alternate name even supported by WeiDU?)

I have also found an error in the SET_2DA tutorial (chapter 10.15). It states SET_2DA_ENTRIES_NOW ~string~ row_count. "row_count" should probably be "col_count".

Imagination is more important than knowledge. Knowledge is limited; imagination encircles the world. - Albert Einstein