Author Topic: READ_2DA_ENTRY_FORMER confusion  (Read 1414 times)

Offline plainab

  • Sasha al'Therin
  • Planewalker
  • *****
  • Posts: 491
    • Infinity Engine Modding
READ_2DA_ENTRY_FORMER confusion
« on: November 11, 2011, 01:01:58 AM »
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
Code: [Select]
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.
Code: [Select]
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 loop
Code: [Select]
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%-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?
My working mods:
an AI Party Script for BG2 game engine DOWNLOAD LINK ONLY!
Interactive Tweaks for BG series with some IWD support. DOWNLOAD LINK ONLY!
Rest For 8 Hours an IWD mod
-------------------------------------------
My contributions: BG1Fixpack, BG1Tweaks
On Hold: Solestia an NPC for SOA
-------------------------------------------
My website: http://sasha-altherin.webs.com

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: READ_2DA_ENTRY_FORMER confusion
« Reply #1 on: November 11, 2011, 02:34:55 PM »
Because it's parsed as "j-"= "1" instead of "j" -= "1"; the same thing happens if you write foo-bar, which is parsed as "foo-bar" instead of "foo" - "bar".

Solution: put some spaces around your variable names. Aside from this bug, I'll make your code more legible.
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

Offline Miloch

  • Barbarian
  • Planewalker
  • *****
  • Posts: 1032
  • Gender: Male
Re: READ_2DA_ENTRY_FORMER confusion
« Reply #2 on: November 20, 2011, 08:18:09 PM »
I'll make your code more legible.
Thanks, man. I've been waiting for someone to offer this. I've got a few dozen kiloblocs for you to go through.

(Did you mean "it'll make your code more legible"?)

Offline plainab

  • Sasha al'Therin
  • Planewalker
  • *****
  • Posts: 491
    • Infinity Engine Modding
Re: READ_2DA_ENTRY_FORMER confusion
« Reply #3 on: November 29, 2011, 09:59:00 PM »
I'll make your code more legible.
Thanks, man. I've been waiting for someone to offer this. I've got a few dozen kiloblocs for you to go through.

(Did you mean "it'll make your code more legible"?)
I think he did mean "it'll make your code more legible" since none of my existing code has gotten any better  :P
My working mods:
an AI Party Script for BG2 game engine DOWNLOAD LINK ONLY!
Interactive Tweaks for BG series with some IWD support. DOWNLOAD LINK ONLY!
Rest For 8 Hours an IWD mod
-------------------------------------------
My contributions: BG1Fixpack, BG1Tweaks
On Hold: Solestia an NPC for SOA
-------------------------------------------
My website: http://sasha-altherin.webs.com

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: