Author Topic: How do I set a variable's name using another variable?  (Read 5559 times)

cmdrmcdonald

  • Guest
How do I set a variable's name using another variable?
« on: November 23, 2016, 07:25:41 AM »
I have a text variable 'colour' which is set to 'red' and another text variable 'note'.  I want to set a text variable 'Note for red' to the value of 'note'.

Ideally in the 'Set a Text Value' dialog I'd set 'Variable Name' to 'Note for {TXT:colour}' but VA doesn't like this.  Is there some way of doing this without manually adding in a bunch of conditionals for each possible value of colour?

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2826
Re: How do I set a variable's name using another variable?
« Reply #1 on: November 23, 2016, 10:59:16 PM »
So, just to be clear, you are wanting to set a variable based on a token?  I believe the validation error you get is that the variable cannot contain colons.  I think that the way things are done now that this might be able to be changed.  I'll take a look.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2826
Re: How do I set a variable's name using another variable?
« Reply #2 on: November 24, 2016, 12:48:34 AM »
This will be in the next release ;)

cmdrmcdonald

  • Guest
Re: How do I set a variable's name using another variable?
« Reply #3 on: November 24, 2016, 04:16:01 AM »
Fantastic news, thanks.  I'll give it a test when available and let you know how it goes.

cmdrmcdonald

  • Guest
Re: How do I set a variable's name using another variable?
« Reply #4 on: November 25, 2016, 07:39:33 AM »
I just tried this with the 1.6.1.2 release and it doesn't appear to work.  I set the variable name to "Material reminder for {TXT:Material reminder material}" and VoiceAttack responded with a popup saying "The Text Value Name must not contain colons if not contained within a token".  Am I doing something wrong?


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Re: How do I set a variable's name using another variable?
« Reply #5 on: November 25, 2016, 08:07:41 AM »
Am I doing something wrong?
It appears it's only possible to use tokens containing colons if all text(excluding spaces) is contained in curly braces.

"{TXT:Test}" works
"a{TXT:Test}" does not
"{TXT:Test}a" does not
"{a}{TXT:Test}" works
"{TXT:Test}{a}" works
"a{TIME}a" works

I doubt it's intentional. For now, because non-token curly braces are discarded, "{Material reminder for} {TXT:Material reminder material}" will do what you want.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2826
Re: How do I set a variable's name using another variable?
« Reply #6 on: November 25, 2016, 09:34:22 AM »
The issue is that if a variable name has a colon in it and it is used somewhere along the line without anybody knowing about it, it may cause problems.  I guess it would be pretty evident if you know what you're doing.  I somehow assumed the entire variable name was going to be a token o_O.  I'll do some extra legwork to make sure that the colon is contained between curly braces and not just, 'starts with curly brace' and 'ends with curly brace'.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2826
Re: How do I set a variable's name using another variable?
« Reply #7 on: November 26, 2016, 07:36:35 PM »
I've fixed this up.  It will be in the next release, however, I went ahead and threw it in the, 'unofficial' bin if you want to make sure it works for you.   

The check was in there to basically keep people from messing themselves up.  There shouldn't be a colon in your variable names since the parsing of tokens with parameters uses colons to delimit the parameters.  The check for a colon in the name is still there, but it's simply now just looking to see if there is both a left and right curly bracket in there anywhere and letting you pass by.  It's kind of there now to just keep people that don't know what's going on to keep them from blowing up.   So, a variable name of, 'hello_}:{' will pass inspection, but if you blow yourself up using that variable name you probably deserve it... j/k.

http://www.voiceattack.com/unofficial