Author Topic: TXTREPLACE Token  (Read 7405 times)

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
TXTREPLACE Token
« on: May 09, 2016, 06:49:59 PM »
I couldn't decide where this should go, as it's not "bug", I guess, and not really a feature request:

I was trying to help out by providing a workaround using {TXTREPLACE:}, however I can't get it to work in any form.

The documentation says:
Quote
{TXTREPLACE:myToken:test:monkey} renders as 'This is a monkey'.

I tried {TXTREPLACE:{CMD}:{CMD_AFTER}:}, {TXTREPLACE:'{CMD}':{CMD_AFTER}:}, {TXTREPLACE:{CMD}:test:blah}, {TXTREPLACE:'{CMD}':test:blah}, and {TXTREPLACE:CMD:test:blah}

I even tried setting a text value to {CMD} and using that, like {TXTREPLACE:TextValue:test:blah}, but that doesn't work either. It always returns "Not set".

So, while I know you said:
Quote from: Gary
I think the only tokens that really takes text are {EXP} and {TXTRANDOM} (not even sure why they are that way... must have seemed good at the time) .  The other tokens that take variable names could accept a token as the variable name.  However, the problem is that it all needs to be reworked to recursively process inner tokens, as what is happening right now is simple find and replace.  You just don't know which order the tokens are being replaced.  {EXP} is processed last, preceded by {TXTRANDOM}, but that still does not help with nested tokens contained in the value parameters.  It's in the higher end of the todo list.

How am I supposed to use this token currently? What am I doing wrong?


EDIT: I remembered seeing in the changelog that replacing with nothing should be possible, sure enough:
Quote
-  Set text feature, 'replace text' now accepts tokens
        in the 'replace' and 'replace with' fields.  'Replace'
        will now accept spaces and 'Replace with' will now
        accept a blank (empty) value.

And yet my question still stands: What am I doing wrong here?

 {TXTREPLACE:{CMD}:{CMD_AFTER}:} looks perfectly valid to me with these new additions, and yet I can't get it to work.
« Last Edit: May 09, 2016, 06:57:55 PM by Pfeil »

BlackJack

  • Jr. Member
  • **
  • Posts: 68
Re: TXTREPLACE Token
« Reply #1 on: May 10, 2016, 01:45:30 PM »
Hello Pfeil,

   you seem to be right.

I tested it as follows:
set "When I say" to: *2*,

The sequence:
Set Text [CMD] to '{CMD}'
Set Text [CMD_AFTER] to '{CMD_AFTER}'     (to make sure we are using real text tokens)
Write '[Purple] TXT:CMD: {TXT:CMD} TXT:CMD_AFTER: {TXT:CMD_AFTER}' to log
Write '[Orange] {TXTREPLACE:CMD:CMD_AFTER:This is a Test}' to log

Than say: 123

The Result is:
123
TXT:CMD: 123 TXT:CMD_AFTER: 3

But if I change "CMD_AFTER" to "3": {TXTREPLACE:CMD:3:This is a Test}

The Result is:
12This is a Test
TXT:CMD: 123 TXT:CMD_AFTER: 3

I do not know how it is to function otherwise.

Blackjack

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: TXTREPLACE Token
« Reply #2 on: May 10, 2016, 05:10:50 PM »
I couldn't decide where this should go, as it's not "bug", I guess, and not really a feature request:

I was trying to help out by providing a workaround using {TXTREPLACE:}, however I can't get it to work in any form.

The documentation says:
Quote
{TXTREPLACE:myToken:test:monkey} renders as 'This is a monkey'.

I tried {TXTREPLACE:{CMD}:{CMD_AFTER}:}, {TXTREPLACE:'{CMD}':{CMD_AFTER}:}, {TXTREPLACE:{CMD}:test:blah}, {TXTREPLACE:'{CMD}':test:blah}, and {TXTREPLACE:CMD:test:blah}

I even tried setting a text value to {CMD} and using that, like {TXTREPLACE:TextValue:test:blah}, but that doesn't work either. It always returns "Not set".

So, while I know you said:
Quote from: Gary
I think the only tokens that really takes text are {EXP} and {TXTRANDOM} (not even sure why they are that way... must have seemed good at the time) .  The other tokens that take variable names could accept a token as the variable name.  However, the problem is that it all needs to be reworked to recursively process inner tokens, as what is happening right now is simple find and replace.  You just don't know which order the tokens are being replaced.  {EXP} is processed last, preceded by {TXTRANDOM}, but that still does not help with nested tokens contained in the value parameters.  It's in the higher end of the todo list.

How am I supposed to use this token currently? What am I doing wrong?


EDIT: I remembered seeing in the changelog that replacing with nothing should be possible, sure enough:
Quote
-  Set text feature, 'replace text' now accepts tokens
        in the 'replace' and 'replace with' fields.  'Replace'
        will now accept spaces and 'Replace with' will now
        accept a blank (empty) value.

And yet my question still stands: What am I doing wrong here?

 {TXTREPLACE:{CMD}:{CMD_AFTER}:} looks perfectly valid to me with these new additions, and yet I can't get it to work.


The {TXTREPLACE} token help is not right.  You had missed the part of the quote from the post in the groups
https://mail.google.com/mail/u/0/#search/pfeil+replace/154347ccf670764f
:

Quote from: Gary
I'll go back and fix the verbiage for the description of that token.  It's worded wrong.  The word, 'token' should be, 'variable'. Thanks for finding that ;)

{TXTREPLACE} does not accept tokens.  It takes a text variable and two literals. I think that I am going to change that to three variables, as literals just do not work right for obvious reasons.  The value of the variable (first parameter) actually processes tokens.  When finished, all three parameters will accept tokens.  The help is just a big mess.

So, set a text variable first:
myVariable = {CMD} 
{TXTREPLACE:myVariable:text to replace:replacement text}


I would suggest just using the 'set a text value' action to do text replacement if you want it to be a little more reliable:






Quote
-  Set text feature, 'replace text' now accepts tokens
        in the 'replace' and 'replace with' fields.  'Replace'
        will now accept spaces and 'Replace with' will now
        accept a blank (empty) value.

This refers to the Set a Text Value action above, not {TXTREPLACE}

Sorry about that!

Gary

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: TXTREPLACE Token
« Reply #3 on: May 10, 2016, 08:19:41 PM »
The help is just a big mess.
I understand that documentation is difficult and labour intensive to maintain, especially with both a stable and a beta version "in the wild".

I will say it is usually my(and I would assume most users') primary reference, as keeping track of everything that has been said on Groups, via Email, and now on the forum, is just not feasible; Particularly with how fast things can change(for the better).

So, set a text variable first:
myVariable = {CMD} 
{TXTREPLACE:myVariable:text to replace:replacement text}

I would suggest just using the 'set a text value' action to do text replacement if you want it to be a little more reliable:
I understand, though what I was trying to do(removing one variable from another) cannot be done until the token accepts variables in at least the "replace" field, as you've suggested could be possible in the future.

Quote
-  Set text feature, 'replace text' now accepts tokens
        in the 'replace' and 'replace with' fields.  'Replace'
        will now accept spaces and 'Replace with' will now
        accept a blank (empty) value.

This refers to the Set a Text Value action above, not {TXTREPLACE}

Sorry about that!
Ah, of course. Now that you've pointed it out I see where I misunderstood.

Personally, If it all possible, I try to use the exact terminology as found in the interface; E.G. "'Set a Text Value' Text Option 'Replace' now accepts tokens". This should make it reasonably unambiguous as to what one is referring.
Which I say to respectfully provide my point of view on the matter, trying and possibly failing not to sound condescending :x

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: TXTREPLACE Token
« Reply #4 on: May 21, 2016, 12:45:43 AM »
{TXTREPLACE} deprecated...  {TXTREPLACEVAR} will now be the preferred token.

It's in the new beta: 

http://voiceattack.com/SMF/index.php?topic=101.0

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: TXTREPLACE Token
« Reply #5 on: May 21, 2016, 02:32:24 PM »
Alright, had a play around, realised it doesn't take tokens, so this is how it works now:
Code: [Select]
Set Text [CMD] to '{CMD}'
Set Text [CMD_AFTER] to ' {CMD_AFTER}'
Set Text [Blank] to ''
Write '[Red] l{TXTREPLACEVAR:CMD:CMD_AFTER:Blank}l' to log