Author Topic: Dynamic Coding (variables, conditions, etc) - New guy needs help  (Read 8861 times)

Sut3k

  • Guest
Hey guys,
Sorry if this problem has been addressed here but I've read up on some of the posts and the help documents and my questions are vague enough I'm having trouble searching for the answers. I've been programming for a long time, but never in VA until about a month ago.

First question is straightforward. I can't get variables to work for me at all.
Why doesnt this work? When I say Test Command, all I get is Does not back. Seems like I am missing something basic here. http://imgur.com/a/Q3tHT

Second question is that the manual talks about Tokens and such and they seem great, but it doesnt go into some key details. Using their example I setup my command of:
[Throttle;Speed] to [10;20;30;40;50;60;70;80;90;100]

Now, this is only useful, if I can retrieve the actual number the commander called and set the throttle to that, but I cant find anyway to do that. The manual's example is eject car [1..100]

Thanks for the help.

iceblast

  • Sr. Member
  • ****
  • Posts: 374
Re: Dynamic Coding (variables, conditions, etc) - New guy needs help
« Reply #1 on: January 13, 2017, 12:33:56 AM »
I think I have the answer to your first question.

You set a small integer, but you're comparing for a regular Integer, easy to overlook.

Code: [Select]
Set small int (condition) [Hardtest] value to 1
Begin Small Integer Compare : [Hardtest] Equals 1
    Say, 'Equals 1'
Else
    Say, 'Does not'
End Condition

Sorry, I can't help with the second question, I have no experience setting up a command like that. I do believe I saw a Youtube video by someone, who set something like that up though.

I'm sure one of the other guys will answer you question though.

Sut3k

  • Guest
Re: Dynamic Coding (variables, conditions, etc) - New guy needs help
« Reply #2 on: January 13, 2017, 08:21:31 AM »
yup! that was it for the first problem; I knew it had to be something simple. Thanks iceblast.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4776
  • RTFM
Re: Dynamic Coding (variables, conditions, etc) - New guy needs help
« Reply #3 on: January 13, 2017, 08:40:25 AM »
I setup my command of:
[Throttle;Speed] to [10;20;30;40;50;60;70;80;90;100]

Now, this is only useful, if I can retrieve the actual number the commander called and set the throttle to that, but I cant find anyway to do that.
You can use the "{CMD}" token to find out what was spoken when the command was triggered(or a default command name if triggered by keyboard), and combine it with the "{TXTNUM:}" token to discard any input that isn't a number:
Code: [Select]
Write '[Blue] {TXTNUM:"{CMD}"}' to log
In this case VoiceAttack will write the number to the log in blue, but you can use that sequence of tokens in many places within VoiceAttack.

If you wanted it as an integer value(so you can do math with it), you can convert the token using the "Convert Text/Token" field in the "Set a Small Integer (Condition) Value" action(Also possible with "Decimal" and "Integer" variables):
Code: [Select]
Set small int (condition) [Throttle] value to the converted value of {TXTNUM:"{CMD}"}
Note that I'm using a "Small Integer" here, because under normal conditions the value will be between -32,768 and +32,767.

If you execute your example using any method other than speech, the filtered number will be "102030405060708090100", which in VoiceAttack will mean the variable is set to "0" as it cannot contain such a large number(though it doesn't have to either, because you can't set the throttle to that value).

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2831
Re: Dynamic Coding (variables, conditions, etc) - New guy needs help
« Reply #4 on: January 13, 2017, 09:48:04 AM »
I've got some stuff in the pipeline that's going to make all this a bit easier.  It's in 'proof-of-concept', but it's getting closer to becoming a thing ;)

Sut3k

  • Guest
Re: Dynamic Coding (variables, conditions, etc) - New guy needs help
« Reply #5 on: January 13, 2017, 06:35:17 PM »
Thanks for the info! I can now get it to log what number I said.

Looking forward to the fancy updates Gary!

I'm still having a bit of trouble with variables though. The log won't show the variable, the TTS won't say it, and my Loop isn't running. What syntax am I missing now?

Code: [Select]
Set small int (condition) [ThrottleRequest] value to the converted value of {TXTNUM:"{CDM}"}
Say, 'Throttle to {TXTNUM:"{ThrottleRequest}"}'
Write '[Blue] Throttle Request = {TXTNUM:"{CMD}"}' to log
Write '[Blue] Throttle Request = [ThrottleRequest]' to log
Write '[Blue] Throttle  = {Throttle}' to log
Begin Small Integer Compare : [Throttle] Has Not Been Set
    Set small int (condition) [Throttle] value to 0
    Write '[Blue] {TXTNUM:[Throttle]}' to log
End Condition
Start Loop While : [Throttle] Is Less Than [ThrottleRequest]
    Write '[Blue] Increasing Speed' to log
    Execute command, '(Throttle Up)' (and wait until it completes)
    Set small int (condition) [Throttle] value as incremented by 10
End Loop
Set small int (condition) [Throttle] value to the value of [ThrottleRequest]

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2831
Re: Dynamic Coding (variables, conditions, etc) - New guy needs help
« Reply #6 on: January 13, 2017, 07:07:47 PM »
The first line has, 'CDM' instead of, 'CMD'.  That could be it...

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4776
  • RTFM
Re: Dynamic Coding (variables, conditions, etc) - New guy needs help
« Reply #7 on: January 13, 2017, 07:17:10 PM »
Code: [Select]
Write '[Blue] Throttle Request = [ThrottleRequest]' to log
Write '[Blue] Throttle  = {Throttle}' to log
The log won't show the variable because you have to specify which type of variable you're trying to use:
Code: [Select]
Write '[Blue] Throttle Request = {SMALL:ThrottleRequest}' to log
Write '[Blue] Throttle  = {SMALL:Throttle}' to log
Also note that you're displaying the value of "Throttle" potentially before you've set it, so it will display "Not Set" when running the command after VoiceAttack has (re)started.

Sut3k

  • Guest
Re: Dynamic Coding (variables, conditions, etc) - New guy needs help
« Reply #8 on: January 14, 2017, 01:25:37 PM »
Ah yes, the infamous dumb-typo bug... Thanks Gary. Now my command is working.

Pfeil, I could use a little help on syntax definitions to help me in the future. For example, the difference between putting something in {} versus [].

Code: [Select]
Write '[Blue] Throttle Request = {Small:ThrottleRequest}' to log
Is currently spitting out
1:22:06 PM - Throttle Request = Small:ThrottleRequest

Also, why do you put quotes around {CMD}? Why doesn't that make it a literal string? What language is all of this based on?

I tend to do things in unconventional ways, or at least try things out of the norm. Knowing some of the details of the rules will help me avoid posting more debugging questions on here or testing out every combination of syntax to get the right one.

Thanks again.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2831
Re: Dynamic Coding (variables, conditions, etc) - New guy needs help
« Reply #9 on: January 14, 2017, 01:46:07 PM »
The {TXTNUM} token requires double quotes around literals and tokens, and not around variables.  The reason the quotes are required around tokens is because tokens can be nested... which means they are re-parsed over and over until all the tokens are resolved.  If what was left over was not in quotes, TXTNUM would interpret that as a variable and then try to resolve it... which will most likely be null (not set).

In other news (good news)... I released a new beta today that has a way to extract the numeric part of your command:

[Throttle;Speed] to [10;20;30;40;50;60;70;80;90;100]

{CMDSEGMENT:0} would be either, 'throttle' or,  'speed', {CMDSEGMENT:1} would be, 'to' and {CMDSEGMENT:2} would yield the numeric part (note the segment number is zero-based). 

I've also just realized that your can also do this now (latest beta lol):

[Throttle;Speed] to [1..10,10]    (note the multiplier)

Hope that helps some!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4776
  • RTFM
Re: Dynamic Coding (variables, conditions, etc) - New guy needs help
« Reply #10 on: January 14, 2017, 02:41:31 PM »
The difference between putting something in {} versus [].
Curly braces are used to denote a token(Basically an inline function, where the token is replaced with the output of said function), whereas block quotes are used in a number of ways, depending on context:
  • Dynamic sections when used in a command name([10;20;30], as you've used already).
  • Dynamic response sections when used in the "Say Something with Text-To-Speech" action([Hello;Hi;Howdy])
  • Keystrokes that cannot be represented by a single character(like [ENTER]) in the "Quick Input" and "Variable Keypress" actions
  • Inline pauses in the "Quick Input" action(Ex: [PAUSE:0.5] will pause one half a second)

Code: [Select]
Write '[Blue] Throttle Request = {Small:ThrottleRequest}' to log
Is currently spitting out
1:22:06 PM - Throttle Request = Small:ThrottleRequest
Tokens are case sensitive.

What language is all of this based on?
Gary's. Magenheimer, not Kildall, may he rest in peace.