first off did some testing of this to help out i30817 over at SHS I tested on BG1, but the code is for BG2...
I was using his initial code and kept getting it to error out. eventually managed to get something that would output the data he wanted, but was unable to get any data from any other row. So I did some further testing.
This patch works and prints out the data as intended COPY_EXISTING ~backstab.2da~ ~override~
COUNT_2DA_COLS max_level
SET real_cols = (%max_level%-1)
READ_2DA_ENTRIES_NOW ~gt#_#backstab~ 3
SPRINT levelup_string ~~
FOR (j=0;j<%real_cols%;j+=1) BEGIN
READ_2DA_ENTRY_FORMER ~gt#_#backstab~ 0 %j% level
READ_2DA_ENTRY_FORMER ~gt#_#backstab~ 1 %j% stab
READ_2DA_ENTRY_FORMER ~gt#_#backstab~ 1 0 class
PATCH_PRINT ~Class: %class% Level: %level% Backstab: %stab%~
END
BUT_ONLY
But i30817 wanted to get the data starting at the end of the rows rather than starting at the beginning.
This code which merely has the values in the FOR loop swapped around to start at the end rather than the beginning errors out.COPY_EXISTING ~backstab.2da~ ~override~
COUNT_2DA_COLS max_level
SET real_cols = (%max_level%-1)
READ_2DA_ENTRIES_NOW ~gt#_#backstab~ 3
SPRINT levelup_string ~~
FOR (j=%real_cols%;j>0;j-=1) BEGIN
READ_2DA_ENTRY_FORMER ~gt#_#backstab~ 0 %j% level
READ_2DA_ENTRY_FORMER ~gt#_#backstab~ 1 %j% stab
READ_2DA_ENTRY_FORMER ~gt#_#backstab~ 1 0 class
PATCH_PRINT ~Class: %class% Level: %level% Backstab: %stab%~
END
BUT_ONLY
Can you explain why this happens? And shouldn't it be fixed if possible?
hmm scratch that, got it to work BUT one thing doesn't make sense about it
working code with high to low FOR loopCOPY_EXISTING ~backstab.2da~ ~override~
COUNT_2DA_COLS max_level
SET real_cols = (%max_level%-1)
READ_2DA_ENTRIES_NOW ~gt#_#backstab~ 3
SPRINT levelup_string ~~
FOR (j=(%real_cols%-1);j>0;j=%j%-1) BEGIN
READ_2DA_ENTRY_FORMER ~gt#_#backstab~ 0 %j% level
READ_2DA_ENTRY_FORMER ~gt#_#backstab~ 1 %j% stab
READ_2DA_ENTRY_FORMER ~gt#_#backstab~ 1 0 class
PATCH_PRINT ~Class: %class% Level: %level% Backstab: %stab%~
END
BUT_ONLY
after I figured out that j had to equal (%real_cols%-1) it would run in an endless loop till I changed j-=1 to j=%j%-1 I'm not too sure why j-=1 didn't work Do you know why j-=1 would cause an endless loop?