Author Topic: STR_VAR and .tra references  (Read 989 times)

Offline Galactygon

  • Modding since 2002
  • Planewalker
  • *****
  • Posts: 378
  • Gender: Male
  • Creator of spells
STR_VAR and .tra references
« on: March 11, 2017, 03:30:34 AM »
Apparently this is something ridiculously simple yet I am having problems trying to do something like this:
Code: [Select]
LAUNCH_PATCH_FUNCTION ~APPLY_DESC_SPL~
STR_VAR desc_text = @17081
END
or
Code: [Select]
LAUNCH_PATCH_FUNCTION ~APPLY_DESC_SPL~
STR_VAR desc_text = "@17081"
END
or
Code: [Select]
LAUNCH_PATCH_FUNCTION ~APPLY_DESC_SPL~
STR_VAR desc_text = EVAL "@17081"
END
without writing an extra line like this:
Code: [Select]
SPRINT a @17081
LAUNCH_PATCH_FUNCTION ~APPLY_DESC_SPL~
STR_VAR desc_text = EVAL "%a%"
END

Offline Gwendolyne_FP

  • Planewalker
  • *****
  • Posts: 66
Re: STR_VAR and .tra references
« Reply #1 on: March 11, 2017, 03:37:59 AM »
use something like that:

Code: [Select]
LPF APPLY_DESC_SPL INT_VAR desc = 17081 END
and in your_function:

Code: [Select]
SET patch_desc = RESOLVE_STR_REF ((AT %desc%))
or even:
Code: [Select]
WRITE_LONG 0x50 RESOLVE_STR_REF ((AT %desc%))
« Last Edit: March 11, 2017, 03:42:07 AM by Gwendolyne_FP »

Offline Wisp

  • Moderator
  • Planewalker
  • *****
  • Posts: 1176
Re: STR_VAR and .tra references
« Reply #2 on: March 11, 2017, 03:42:13 AM »
Or, more simply:
Code: [Select]
LPF APPLY_DESC_SPL INT_VAR desc_text = RESOVLVE_STR_REF (@17081) END

Offline Galactygon

  • Modding since 2002
  • Planewalker
  • *****
  • Posts: 378
  • Gender: Male
  • Creator of spells
Re: STR_VAR and .tra references
« Reply #3 on: March 11, 2017, 03:49:34 AM »
I am specifically trying to do stuff in STR_VAR instead of INT_VAR before adding a new .tlk entry (i.e. by reading off spell data first and setting variables in the .tra entries). I want to avoid adding spurious entries to the .tlk files since RESOVLVE_STR_REF is automatically going to add whatever is in there.

I am trying to get my head around this old thread. Is it even possible to use .tra entries for STR_VAR?

Offline Gwendolyne_FP

  • Planewalker
  • *****
  • Posts: 66
Re: STR_VAR and .tra references
« Reply #4 on: March 11, 2017, 04:13:42 AM »
In this case, you could adapt this piece of code I use to create items from an array:

Code: [Select]
PATCH_IF (STRING_LENGTH "%data_58%" > 6) BEGIN // the first GW_Items.tra entry is @8000001
SET GW_newitem_name1 = RESOLVE_STR_REF ((AT %data_58%))
END ELSE BEGIN // looks for the reference in dialog.tlk
SET GW_nvitem_name1 = EVAL "%data_58%"
END
END

Otherwise, this is another code I use to install item descriptions whatever the game is (EE or no)

Code: [Select]
/* ===================================================================================================================== *
 * FONCTION GW_UPDATE_ITM_DESCRIPTION_TO_BGEE : AJUSTE la DESCRIPTION des OBJETS au format EE.                           *
 * --------------------------------------------------------------------------------------------------------------------- *
 * Reads the variable GW_desc_to_update (reference @nn) in GW_Items.tra and alters it into the variable GW_desc_updated. *
 * ===================================================================================================================== *
 * FONCTION GW_WRITE_ITM_DESCRIPTIONS_TO_BGEE : ÉCRIT les DESCRIPTIONS des OBJETS au format EE.                          *
 * --------------------------------------------------------------------------------------------------------------------- *
 * Reads the variables GW_desc_to_update and GW_undesc_to_update (reference @nn) in GW_Items.tra, alters them if needed, *
 * then writes them in the ITM file.                                                                                     *
 * ===================================================================================================================== */

DEFINE_PATCH_FUNCTION ~GW_UPDATE_ITM_DESCRIPTION_TO_BGEE~
STR_VAR GW_desc_to_update = ~~ // reference in format @123 or #123
RET GW_desc_updated // returns modified text
BEGIN

INNER_ACTION BEGIN
ACTION_IF (~%GW_desc_to_update%~ STRING_COMPARE_REGEXP ~^[@#]-?[0-9]+$~ == 0) BEGIN
<<<<<<<< .../inlined/GW_%GW_desc_to_update%.tpp
OUTER_SPRINT GW_desc_updated
>>>>>>>>
SILENT
COPY - ~.../inlined/GW_%GW_desc_to_update%.tpp~ ~.../inlined/GW_%GW_desc_to_update%.tpp~
INSERT_BYTES SOURCE_SIZE (STRING_LENGTH ~%GW_desc_to_update%~)
WRITE_ASCIIE SOURCE_SIZE ~%GW_desc_to_update%~
VERBOSE
INCLUDE ~.../inlined/GW_%GW_desc_to_update%.tpp~
OUTER_SPRINT usab @8999991 // ~[Uu]tilisable[ %tab%]+[Pp]ar[ %tab%]*:~ = ~Usable[ %tab%]+[Bb]y[ %tab%]*:~
OUTER_SPRINT unus @8999992 // ~\([Nn]on[ %tab%]+\|[Ii]n\)[Uu]tilisable[ %tab%]+[Pp]ar[ %tab%]*:~ = ~\(Not[ %tab%]+\|Un\)[Uu]sable[ %tab%]+[Bb]y[ %tab%]*:~
OUTER_PATCH_SAVE GW_desc_updated ~%GW_desc_updated%~ BEGIN // Suppression de toutes les références aux classes et aux kits pouvant ou pas utiliser l'objet.
REPLACE_TEXTUALLY ~\(\([%LNL%%MNL%%WNL%][ %TAB%]*\(%usab%\|%unus%\)[ %TAB%]*\)\(\([%LNL%%MNL%%WNL%].*\)*\)?\)~  ~~
END
END ELSE BEGIN
OUTER_SPRINT GW_desc_updated ~none~
END
END // of INNER_ACTION

END // of DEFINE_PATCH_FUNCTION


DEFINE_PATCH_FUNCTION ~GW_WRITE_ITM_DESCRIPTIONS_TO_BGEE~
STR_VAR GW_desc_to_update = ~~ // reference in format @123 or #123
GW_undesc_to_update = ~~ // reference in format @123 or #123
BEGIN
PATCH_IF (ENGINE_IS ~bgee bg2ee eet~) OR GAME_INCLUDES ~sod~ BEGIN
SPRINT GWdesc "none"
SPRINT GWundesc "none"
PATCH_IF ("%GW_desc_to_update%" STRING_COMPARE_REGEXP ~^[@#]-?[0-9]+$~ = 0) AND ("%GW_desc_to_update%" STR_CMP ~~) BEGIN
LPF ~GW_UPDATE_ITM_DESCRIPTION_TO_BGEE~ STR_VAR GW_desc_to_update = EVAL "%GW_desc_to_update%" RET GWdesc = GW_desc_updated END
END ELSE BEGIN
SPRINT GWdesc ~none~
END
PATCH_IF ("%GW_undesc_to_update%" STRING_COMPARE_REGEXP ~^[@#]-?[0-9]+$~ = 0) AND ("%GW_undesc_to_update%" STR_CMP ~~) BEGIN
LPF ~GW_UPDATE_ITM_DESCRIPTION_TO_BGEE~ STR_VAR GW_desc_to_update = EVAL "%GW_undesc_to_update%" RET GWundesc = GW_desc_updated END
END ELSE BEGIN
SPRINT GWundesc ~none~
END
PATCH_IF ("%GWdesc%" STR_CMP "none") BEGIN SAY_EVALUATED DESC ~%GWdesc%~ END
PATCH_IF ("%GWundesc%" STR_CMP "none") BEGIN SAY_EVALUATED UNIDENTIFIED_DESC ~%GWundesc%~ END

END ELSE BEGIN // BG2 ou BGT
PATCH_IF ("%GW_desc_to_update%" STRING_COMPARE_REGEXP ~^[@#]-?[0-9]+$~ = 0) AND ("%GW_desc_to_update%" STR_CMP ~~) BEGIN
WRITE_LONG 0x54 RESOLVE_STR_REF (%GW_desc_to_update%) // %GW_desc_updated%
END
PATCH_IF ("%GW_undesc_to_update%" STRING_COMPARE_REGEXP ~^[@#]-?[0-9]+$~ = 0) AND ("%GW_undesc_to_update%" STR_CMP ~~) BEGIN
WRITE_LONG 0x50 RESOLVE_STR_REF (%GW_undesc_to_update%) // %GW_undesc_updated%
END

END // of PATCH_IF (ENGINE_IS ~bgee bg2ee eet~) OR GAME_INCLUDES ~sod~

END // of DEFINE_PATCH_FUNCTION

Some comments are in french but you should easily understand the code. ;)
« Last Edit: March 11, 2017, 05:31:02 AM by Gwendolyne_FP »

Offline Galactygon

  • Modding since 2002
  • Planewalker
  • *****
  • Posts: 378
  • Gender: Male
  • Creator of spells
Re: STR_VAR and .tra references
« Reply #5 on: March 11, 2017, 05:11:27 AM »
Thanks for the help Gwendo, the (AT variable) does it. I did not know about it before. I now have:
Code: [Select]
COPY_EXISTING ~%spell_res%.spl~ ~override~
LAUNCH_PATCH_FUNCTION ~APPLY_DESC_SPL~
INT_VAR desc_traentry = 17081 // tra entry number
END

Along with:
Code: [Select]
DEFINE_PATCH_FUNCTION ~APPLY_DESC_SPL~
INT_VAR
name_strref = "-1" // Use a specific string or RESOVLVE_STR_REF ()
desc_strref = "-1" // Use a specific string or RESOVLVE_STR_REF ()
name_traentry = "-1" // Use a .tra entry number (i.e. 0 for @0)
desc_traentry = "-1" // Use a .tra entry number (i.e. 0 for @0)
STR_VAR
name_text = "" // Set strings brute force method (not recommended)
desc_text = "" // Set strings brute force method (not recommended)
BEGIN
PATCH_IF
("%SOURCE_FILE%" STRING_MATCHES_REGEXP "^.+\.spl$" = 0 AND BUFFER_LENGTH > 0x71)
AND (NOT "%name_text%" STRING_EQUAL_CASE "" OR NOT "%desc_text%" STRING_EQUAL_CASE ""
OR name_strref >= 0 OR desc_strref >= 0 OR name_traentry >= 0 OR desc_traentry >= 0)
BEGIN // Sanity check
// Write name
PATCH_IF name_strref >= 0 BEGIN // If %name_strref% is set
SAY NAME1 name_text
END ELSE
PATCH_IF name_traentry >= 0 BEGIN // If %name_traentry% is set
SPRINT name_text (AT name_traentry)
END
PATCH_IF NOT "%name_text%" STRING_EQUAL_CASE "" BEGIN // If %name_text% is set
SAY_EVALUATED NAME1 "%name_text%"
END
// Write description
PATCH_IF desc_strref >= 0 BEGIN // If %desc_strref% is set
SAY UNIDENTIFIED_DESC desc_text
END ELSE
PATCH_IF desc_traentry >= 0 BEGIN // If %desc_traentry% is set
SPRINT desc_text (AT desc_traentry)
END
PATCH_IF NOT "%desc_text%" STRING_EQUAL_CASE "" BEGIN // If %desc_text% is set
// Record spell-related data here
SAY_EVALUATED UNIDENTIFIED_DESC "%desc_text%"
END
END
END

 

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