Slightly to my surprise, I think I've found a bug in SET_2DA_ENTRY.
Reproduction: take the BG2EE 'wish.2da' file. It's a standard 2da:
2DA V1.0
*
1 2 3 4
1 23 23 23 22
2 24 24 24 24
3 25 10 25 30
4 26 26 33 26
...
Say we want to change the last column header from '4' to '-1'. (There's no earthly reason to do this, it's just to demonstrate the bug). You'd expect this to work:
SET_2DA_ENTRY 0 3 4 "-1"
But if you do that, it actually changes the penultimate column header:
2DA V1.0
*
1 2 -1 4
1 23 23 23 22
2 24 24 24 24
3 25 10 25 30
4 26 26 33 26
...
(If you try SET_2DA_ENTRY 0 4 4 "-1", you get an install-time error.)
If you delete the whitespace before the column entry, like this, SET_2DA_ENTRY works correctly:
2DA V1.0
*
1 2 3 4
1 23 23 23 22
2 24 24 24 24
3 25 10 25 30
4 26 26 33 26
...
So I assume some bit of the SET_2DA_ENTRY internal is treating the whitespace as an extra column.
(I don't think there's anything special about wish.2da here - I actually discovered it on thiefscl.2da.)
The workaround is to use SET_2DA_ENTRY_LATER:
SET_2DA_ENTRY_LATER wish_out 0 3 "-1"
SET_2DA_ENTRIES_NOW wish_out 4