Pocket Plane Group
Friends and Neighbors => Weimer Republic (WeiDU.org) => WeiDU => Topic started by: DavidW on August 11, 2021, 06:42:26 AM
-
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
-
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
...
FWIW, the same bug occurs if you run
SET_2DA_ENTRY 2 3 0 "-1"
-
This is not a bug I can fix without risking random mods catching fire and falling out of the sky.
SET_2DA_ENTRY has 2 code paths. The so-called "fast SET_2DA_ENTRY" is used by default and does not distinguish properly between leading and separating whitespace. The "old method" is used if "fast SET_2DA_ENTRY" fails and does not have this problem. The "fast" and "old" methods consequently count count columns differently, the "fast" method arguably does so incorrectly, but I can't fix it without changing de facto expected behaviour.
SET_2DA_ENTRY 0 4 4 "-1" fails because it's out-of-bounds to the code that counts columns and rows, as the 2DA count starts from 0.
SET_2DA_ENTRY_LATER/NOW does not have this problem because it uses its own code path (analogous to the "old method" of SET_2DA_ENTRY).
-
NO_SET_2DA_ENTRY_BUG ?
(ducks)
-
Yeah, I could make it opt-in.
-
Huh.
Does this affect READ_2DA_ENTRY as well? Could explain some difficulties I've been having.
EDIT - nope, after more testing, READ seems to work fine.