Author Topic: Feature Request: More Things Accepted by STR_VAR  (Read 4729 times)

Offline Mike1072

  • Planewalker
  • *****
  • Posts: 298
  • Gender: Male
Feature Request: More Things Accepted by STR_VAR
« on: March 25, 2010, 03:16:14 AM »
Can STR_VAR be modified to accept .tra references?

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: Feature Request: More Things Accepted by STR_VAR
« Reply #1 on: March 25, 2010, 07:56:45 AM »
It's possible, but it'd mess up traify (the same bug happens with SPRINT).
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 Mike1072

  • Planewalker
  • *****
  • Posts: 298
  • Gender: Male
Re: Feature Request: More Things Accepted by STR_VAR
« Reply #2 on: April 29, 2010, 01:15:43 AM »
I didn't feel like causing a fuss before, but I do now. :) I think this downside would be acceptable.  Anyone else have an opinion?

I'd like to use this feature on a function that deals with adding strings to dialog.tlk as part of editing a 2DA file.  I can imagine other hypothetical cases where this could be useful as well.

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: Feature Request: More Things Accepted by STR_VAR
« Reply #3 on: April 29, 2010, 07:02:20 AM »
Anyone else have an opinion?
I do, and my opinion is "don't make traify even buggier". The closest I can do is to allow @variable in both .d and .tp*:

SET x = 5 + y
<...>
SAY NAME @x

however, expressions like @(x + 2) are not allowed.
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 Mike1072

  • Planewalker
  • *****
  • Posts: 298
  • Gender: Male
Re: Feature Request: More Things Accepted by STR_VAR
« Reply #4 on: April 29, 2010, 08:00:38 AM »
Ugh, I give up.  Functions are not always better than macros, even when they should be.
« Last Edit: April 29, 2010, 08:11:10 AM by Mike1072 »

Offline Miloch

  • Barbarian
  • Planewalker
  • *****
  • Posts: 1032
  • Gender: Male
Re: Feature Request: More Things Accepted by STR_VAR
« Reply #5 on: May 01, 2010, 01:35:28 PM »
I thought SPRINT var @n worked now, or is it some other workaround?

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: Feature Request: More Things Accepted by STR_VAR
« Reply #6 on: May 01, 2010, 01:45:42 PM »
SPRINT VAR @n always worked (unfortunately).
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 Galactygon

  • Modding since 2002
  • Planewalker
  • *****
  • Posts: 378
  • Gender: Male
  • Creator of spells
Re: Feature Request: More Things Accepted by STR_VAR
« Reply #7 on: July 09, 2010, 12:55:17 PM »
The closest I can do is to allow @variable in both .d and .tp*:

SET x = 5 + y
<...>
SAY NAME @x

however, expressions like @(x + 2) are not allowed.

I would like to make @variable a request; it would save me hundreds of lines of code.

-Galactygon

Offline Mike1072

  • Planewalker
  • *****
  • Posts: 298
  • Gender: Male
Re: Feature Request: More Things Accepted by STR_VAR
« Reply #8 on: July 09, 2010, 01:22:44 PM »
I ended up creating this function to help do what I needed.

Code: [Select]
DEFINE_PATCH_FUNCTION ~REF2STR~ // given tra reference, strref, or string, returns appropriate string
  STR_VAR ref = ~~ // e.g. ~@123~, ~#9241~, or ~Anything that isn't numbers preceded by @ or # is a string, like this is!~
  RET str
BEGIN
  PATCH_IF ((~%ref%~ STRING_MATCHES_REGEXP ~[@#]-?[0-9]+~) == 0) BEGIN
    INNER_ACTION BEGIN
      <<<<<<<< .../inlined/mi_ref2str.tph
        OUTER_SPRINT str %ref%
      >>>>>>>>
      COPY - ~.../inlined/mi_ref2str.tph~ ~.../inlined/mi_ref2str.tph~
        EVALUATE_BUFFER
      REINCLUDE ~.../inlined/mi_ref2str.tph~
    END
  END
  ELSE BEGIN
    TEXT_SPRINT str ~%ref%~
  END
END

Then I could sneak tra references and strrefs into functions inside of a string.
« Last Edit: July 09, 2010, 01:27:55 PM by Mike1072 »

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: Feature Request: More Things Accepted by STR_VAR
« Reply #9 on: July 09, 2010, 08:51:09 PM »
Done. Can use all of @~var~, @"var", @%var%, @~%var%~ and @"%var%" in .d, .baf and .tp*.
Code: [Select]
<<<<<<<< a.d
BEGIN asd
IF ~~ THEN foo
 SAY @~%asd%~
IF ~~ THEN EXIT
END
>>>>>>>>

<<<<<<<< a.baf
IF
  True()
THEN
  RESPONSE #100
    DisplayStringHead(Myself,@%asd%)
END
>>>>>>>>

OUTER_SET asd=0
COMPILE ~a.d~ ~a.baf~

PRINT @"asd"
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 Galactygon

  • Modding since 2002
  • Planewalker
  • *****
  • Posts: 378
  • Gender: Male
  • Creator of spells
Re: Feature Request: More Things Accepted by STR_VAR
« Reply #10 on: July 10, 2010, 04:55:16 AM »
Thanks. Is there any way to check if %variable% exists in the .tra file?

Code: [Select]
PATCH_IF TRA_ENTRY_EXISTS variable BEGIN
SAY 0x00 @variable
END

-Galactygon

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: Feature Request: More Things Accepted by STR_VAR
« Reply #11 on: July 10, 2010, 04:59:47 AM »
Sure, can do.

TRA_ENTRY_EXISTS (variable_name tra_file...)
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 Galactygon

  • Modding since 2002
  • Planewalker
  • *****
  • Posts: 378
  • Gender: Male
  • Creator of spells
Re: Feature Request: More Things Accepted by STR_VAR
« Reply #12 on: July 10, 2010, 05:14:32 AM »
Thanks.

-Galactygon

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: Feature Request: More Things Accepted by STR_VAR
« Reply #13 on: July 10, 2010, 09:17:32 AM »
I had to change the syntax slightly because I HATE FRENCH PEOPLE. Rather than the sleek @"foo" you need to write (AT "foo").

Sample code:
Code: [Select]
<<<<<<<< standard.tra
@0 = ~lolwut?~
>>>>>>>>

LOAD_TRA standard.tra

<<<<<<<< has_zero.tra
@0 = ~lolwat?~
>>>>>>>>

<<<<<<<< no_zero.tra
>>>>>>>>

OUTER_SET asd=0
OUTER_SET foo=1

PRINT (AT asd) // @var-like construct works in .tp*

<<<<<<<< test.baf
IF
THEN
RESPONSE #100
DisplayString(Myself,(AT "asd")) // @var-like construct works in .baf
END
>>>>>>>>

<<<<<<<< test.d
BEGIN asd
IF ~~ THEN BEGIN S
  SAY (AT asd) // @var-like construct works in .d
++ (AT asd) EXIT
END
>>>>>>>>

COMPILE ~test.baf~ ~test.d~


ACTION_IF TRA_ENTRY_EXISTS (0) THEN BEGIN // true: @0 is loaded
PRINT ~ok~
END

ACTION_IF TRA_ENTRY_EXISTS (asd) THEN BEGIN // true: asd = 0 and @0 is loaded
PRINT ~ok~
END

ACTION_IF TRA_ENTRY_EXISTS (asd ~has_zero.tra~) THEN BEGIN // true: asd = 0 and @0 is in has_zero.tra
PRINT ~ok~
END

ACTION_IF TRA_ENTRY_EXISTS (asd ~has_zero.tra~ ~missing.tra~) THEN BEGIN // true: asd = 0 and one of the listed files contains @0
PRINT ~ok~
END

ACTION_IF TRA_ENTRY_EXISTS (asd not_zero.tra) THEN BEGIN // false: asd = 0 and @0 is not in not_zero.tra
PRINT ~nok~
END

ACTION_IF TRA_ENTRY_EXISTS (asd missing.tra) THEN BEGIN // false: missing.tra doesn't exist, thus it doesn't contain @0
PRINT ~nok~
END

ACTION_IF TRA_ENTRY_EXISTS (foo) THEN BEGIN // false: foo = 1 and @1 isn't currently defined
PRINT ~nok~
END

ACTION_IF TRA_ENTRY_EXISTS (psd) THEN BEGIN // false: psd isn't a valid integer
PRINT ~nok~
END
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 Galactygon

  • Modding since 2002
  • Planewalker
  • *****
  • Posts: 378
  • Gender: Male
  • Creator of spells
Re: Feature Request: More Things Accepted by STR_VAR
« Reply #14 on: July 22, 2010, 02:40:48 AM »
Can you add this one too?

APPEND ~SOME2DA.2da~ ~Test @1~

-Galactygon

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: Feature Request: More Things Accepted by STR_VAR
« Reply #15 on: July 22, 2010, 02:58:04 AM »
No, use APPEND + COPY_EXISTING REPLACE.
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 Galactygon

  • Modding since 2002
  • Planewalker
  • *****
  • Posts: 378
  • Gender: Male
  • Creator of spells
Re: Feature Request: More Things Accepted by STR_VAR
« Reply #16 on: July 22, 2010, 03:24:33 AM »
I know. That's 4 lines of code instead of 1.

-Galactygon

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: Feature Request: More Things Accepted by STR_VAR
« Reply #17 on: July 22, 2010, 03:57:13 AM »
Actually, 3 lines (or even 2 with OUTER_SPRINT + APPEND)  :)

However, I can't code this in a satisfactory way - I can certainly add it as a special case to APPEND (and/or other individual commands), but (because of limitations in OCaml) I can't add it to the generic evaluate_variables function (which would be the natural solution to make that kind of evaluation generic).
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).

 

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