Jump to content
erebusant

How to replace a strref in a .2da file?

Recommended Posts

In the following 2da the 82714 refers to a strref in my dialog.tlk. How would I code a patch to replace this strref with different text that is not yet part of my dialog.tlk using a .tra file?

 

2DA V1.0
*NAERIEL
					0		   1
SWITCH				  DEFAULT	 DEFAULT
DEFAULT				 71020	   82714
DWARF				   0		   0
ELF					 0		   0
HALFELF				 0		   0
HALFLING				0		   0
GNOME				   0		   0
HUMAN				   0		   0
HALFORC				 0		   0
MAGE					0		   0
FIGHTER				 0		   0
CLERIC				  0		   0
THIEF				   0		   0
BARD					0		   0
PALADIN				 0		   0
FIGHTER_MAGE			0		   0
FIGHTER_CLERIC		  0		   0
FIGHTER_THIEF		   0		   0
FIGHTER_MAGE_THIEF	  0		   0
DRUID				   0		   0
RANGER				  0		   0
MAGE_THIEF			  0		   0
CLERIC_MAGE			 0		   0
CLERIC_THIEF			0		   0
FIGHTER_DRUID		   0		   0
FIGHTER_MAGE_CLERIC	 0		   0
CLERIC_RANGER		   0		   0

Edited by erebusant

Share this post


Link to post

holy cow...

 

I don't know ;)

 

SET_2DA_ENTRY looks like it only takes number values, not .tra entries... better check with the bigg.

 

Ascension64's (or SirBillyBob's, but I think Ascension64's) code for using SET_2DA_ENTRY:

 

  COPY_EXISTING ~pdialog.2da~ ~override~
COUNT_2DA_ROWS 8 "cnt_row"
FOR ( cnt=0; cnt<"%cnt_row%"; cnt=cnt+1 ) BEGIN
  READ_2DA_ENTRY "%cnt%" 0 8 "pd_name"
  PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "MONTARON")=0) BEGIN
   SET_2DA_ENTRY "%cnt%" 3 8 "MONTAD"
  END
  PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "KAGAIN")=0) BEGIN
   SET_2DA_ENTRY "%cnt%" 3 8 "KAGAID"
  END
etc.
 END
 BUT_ONLY_IF_IT_CHANGES
END

 

but I have not experimented with attempting to insert a .tra reference.

 

It looks like you may have to add the .tra entry to the dialog.tlk, then determine the strref (get sttref), then SET_2DA_ENTRY.

 

 

Hopefully someone who really understand this better will be able to tell me I am completely wrong :band:

Edited by cmorgan

Share this post


Link to post

REPLACE existingText ~new string~ replaces existingText with the string reference of ~new string~

 

I wouldn't necessarily recommend running REPLACE 82714 ~My new Aerie epilogue.~, but it's along the lines of what you want. Somebody else can pop in with snazzy code that will work for all users, even ones without BG2 installed. ;-)

Edited by devSin

Share this post


Link to post
REPLACE existingText ~new string~ replaces existingText with the string reference of ~new string~

 

I wouldn't necessarily recommend running REPLACE 82714 ~My new Aerie epilogue.~, but it's along the lines of what you want. Somebody else can pop in with snazzy code that will work for all users, even ones without BG2 installed. ;-)

I'm working on a revamp of Ascension that doesn't overwrite, and perhaps will be able to be adapted for BP as well. Just using the existing code in v1.41 works fine along with the.tra when you copy a known strref in a 2da, however if you use COPY_EXISTING with your particular epilogue.2da, the strrefs are (or may be) completely out of alignment (ie; in my install AERIEND1.2da my strref is 73916) 82714 does not exist. I guess I'm looking for a way to dynamically read the strref, whatever it may be to replace it.

Share this post


Link to post
COPY_EXISTING ~FILE_NAME.2da~		 ~override~
 SET_2DA_ENTRY 4 2 1 ~-blabla-~
 REPLACE ~-blabla-~ ~My new Aerie epilogue.~

Share this post


Link to post
I'm working on a revamp of Ascension that doesn't overwrite, and perhaps will be able to be adapted for BP as well.

Oh yes, please. Don't forget to grab he latest DS as well. :band:

Share this post


Link to post
COPY_EXISTING ~FILE_NAME.2da~		 ~override~
 SET_2DA_ENTRY 4 2 1 ~-blabla-~
 REPLACE ~-blabla-~ ~My new Aerie epilogue.~

Please correct me where I interpret this wrong. I just want to be certain I'm understanding what I'm doing instead of just doing,,, :band:

COPY_EXISTING ~FILE_NAME.2da~	 ~override~ //Makes backup of original file
SET_2DA_ENTRY 4 2 1 ~suchandso~ //Takes the 4th row, looks for 2 columns, and sets the entry (whatever it may be) in the column headed "1" with an abritrary entry  ~suchandso~
REPLACE ~suchandso~ ~My new Aerie epilogue.~ // Replaces the abitrary entry from the previous line with the new text of the new Aerie Epilogue (and may I use the @1234 (or whatever my .tra file has)) in place of the ~My new Aerie Epilogue.~? (ie; REPLACE ~suchandso~  @1234)
BUT_ONLY_IF_IT_CHANGES

Edited by erebusant

Share this post


Link to post

SET_2DA_ENTRY row(from0) column(from0) columnCount(from1) newEntry

 

SET_2DA_ENTRY 4 2 1 newEntry sets the third column (0 1 2) of the fifth row (0 1 2 3 4) containing at least one column (1) to newEntry. You could also use SET_2DA_ENTRY 1 2 3 newEntry in the file posted (both will modify the whitespace-delimited entry "82714").

 

REPLACE text ~my string~ replaces every occurrence of text with the string reference for ~my string~ (WeiDU will first see if it's an existing string, then append a new string to dialog.tlk if it isn't; in either case, ~my string~ is the reference for the string in dialog.tlk). REPLACE text @1 will behave identically (as long as @1 is ~my string~ in a loaded TRA).

Edited by devSin

Share this post


Link to post
SET_2DA_ENTRY row(from0) column(from0) columnCount(from1) newEntry

 

SET_2DA_ENTRY 4 2 1 newEntry sets the third column (0 1 2) of the fifth row (0 1 2 3 4) containing at least one column (1) to newEntry. You could also use SET_2DA_ENTRY 1 2 3 newEntry in the file posted (both will modify the whitespace-delimited entry "82714").

 

REPLACE text ~my string~ replaces every occurrence of text with the string reference for ~my string~ (WeiDU will first see if it's an existing string, then append a new string to dialog.tlk if it isn't; in either case, ~my string~ is the reference for the string in dialog.tlk). REPLACE text @1 will behave identically (as long as @1 is ~my string~ in a loaded TRA).

Ahh,,,perfect sense now. So my code to append my existing AERIEND2.2DA with the original Weimer Ascension epilogue using his existing .tra in his package will now look like so:

COPY_EXISTING ~AERIEND2.2da~	~override~
 SET_2DA_ENTRY 4 2 1 ~NEWEPI~
 REPLACE ~NEWEPI~ @82715
BUT_ONLY_IF_IT_CHANGES

and so on and so forth with the rest of the Ascension epilogues,,,

Thank You!! :band:

Edited by erebusant

Share this post


Link to post

As long as @82715 is the TRA reference (@82715=~my string~), that would work.

 

You might want something a bit more unique than NEWEPI (REPLACE really is just glorified search/replace, meaning MYNEWEPILOGUE in the same file would be replaced with MY12345LOGUE, where 12345 is the string reference of the ~my string~ string). You'll never, ever actually have a problem with it, but better safe than sorry, I guess. (Something wacky like Asc_Aerie_Epi or whatever you can think of is pretty much guaranteed to be entirely unique.)

Share this post


Link to post

Bah, prefix shmefix. :)

 

Be warned that all prefixes which might be considered profane are reserved by me. BE WARNED!

Share this post


Link to post

Nothing profane, sadly,,, :band:

This seems do do the trick:

COPY_EXISTING ~VICONND1.2DA~	~override~
 SET_2DA_ENTRY 4 2 1 ~EA_Asc_Viconia_Epi~
 REPLACE ~EA_Asc_Viconia_Epi~ @82728
BUT_ONLY_IF_IT_CHANGES

COPY_EXISTING ~VICONND1.2DA~	~override/VICONND3.2DA~
 SET_2DA_ENTRY 4 2 1 ~EA_Asc_Viconia_Epi~
 REPLACE ~EA_Asc_Viconia_Epi~ @82729

COPY_EXISTING ~IMOENND.2DA~	~override/IMOENFND.2DA~
 SET_2DA_ENTRY 4 2 1 ~EA_Asc_Imoen_Epi~
 REPLACE ~EA_Asc_Imoen_Epi~ @82730

COPY_EXISTING ~IMOENND.2DA~	~override~
 SET_2DA_ENTRY 4 2 1 ~EA_Asc_Imoen_Epi~
 REPLACE ~EA_Asc_Imoen_Epi~ @82731
BUT_ONLY_IF_IT_CHANGES

Share this post


Link to post
Bah, prefix shmefix. :band:

 

Be warned that all prefixes which might be considered profane are reserved by me. BE WARNED!

Like SinAccursedHitMeWithYourRhythmStickWithACherryOnTopEpilogue.

Share this post


Link to post
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...