Author Topic: WITH_TRA  (Read 1363 times)

Offline Gwendolyne_FP

  • Planewalker
  • *****
  • Posts: 66
WITH_TRA
« on: November 09, 2016, 04:31:00 AM »
Maybe because English is not my native language, I don't understand the purpose of the following description:

Quote
Creates a new TRA scope copied from the surrounding scope, loads all traName files (variable substitution is done; the file can be inlined) and evaluates the TP2 Actions. When WITH_TRA exits, the new TRA scope is discarded, that is, all TRA changes made by WITH_TRA or any of its enclosed actions are forgotten.

Is it a substitution for COMPILE .... USING ?

I didn't find a single tp2 using it.

Could you clarify my misunderstanding and give me a simple and straightforward example explaining how and when it would be smart to use it ?

Thanks.
« Last Edit: November 09, 2016, 11:34:13 AM by Gwendolyne_FP »

Offline Argent77

  • Planewalker
  • *****
  • Posts: 187
Re: WITH_TRA
« Reply #1 on: November 09, 2016, 10:54:29 AM »
I see WITH_TRA as a more general replacement of the "USING traFile" parameter (which is only available for a few selected TP2 actions).

Instead of writing
Code: [Select]
COMPILE ~mydialog.d~ USING ~mylines.tra~
OUTER_SET strref = RESOLVE_STR_REF(@1234)

and complaining that RESOLVE_STR_REF() can't load lines from custom TRA files, you can write the following code:
Code: [Select]
WITH_TRA ~mylines.tra~ BEGIN
  COMPILE ~mydialog.d~
  OUTER_SET strref = RESOLVE_STR_REF(@1234)
END

WITH_TRA is a new feature since WeiDU v240, so there aren't many mods using it already.

Offline Wisp

  • Moderator
  • Planewalker
  • *****
  • Posts: 1176
Re: WITH_TRA
« Reply #2 on: November 12, 2016, 05:14:44 AM »
It's a good idea to consider WITH_TRA whenever you have more than a single TRA file. Generally, WITH_TRA obsoletes USING (and to a some degree also LOAD_TRA). Additionally, since WITH_TRA has local scoping and can be nested, you do not necessarily need to worry about keeping your different TRA files free of overlap (e.g., you can start all your TRA files at 0).

As an example, I have this code in aTweaks:
Code: [Select]
  COPY_EXISTING baldur.bcs override
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~\(SetGlobal("drowEraseJournal","GLOBAL",2)\)~ ~EraseJournalEntry(@58) EraseJournalEntry(@59) \1~
    END
  BUT_ONLY
@58 and@59 are pulled from a component-specific TRA file. Before, you needed to have them in setup.tra (e.g., QuestPack had a lot of this) and somehow cope with the associated difficulties (say, the need to have different text encoded in different charsets), or you have to do like me and use a very ugly hack involving LOAD_TRA. Now, you can just wrap the action in WITH_TRA and neatly solve the problem that way.
« Last Edit: November 12, 2016, 05:20:09 AM by Wisp »

Offline Gwendolyne_FP

  • Planewalker
  • *****
  • Posts: 66
Re: WITH_TRA
« Reply #3 on: November 18, 2016, 02:03:22 PM »
Sorry for the delay. I forgot to answer.

Thanks for the examples. As I use a lot LOAD_TRA, I see now how I can use WITH_TRA. ;)

 

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)?: