Author Topic: NEW USERS: Variables in VoxCommando --> cool things in {curly brackets}  (Read 6866 times)

0 Members and 1 Guest are viewing this topic.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Why do we care about variables?

Let's say I want VoxCommando to tell me the time. When writing my command, my watch tells me it's 9:00 AM. Obviously I don't want to write a command rule that says:

"The time is 9:00 AM".

Instead, I will use a standard variable that always returns the current time.

"The time is {ShortTime}."

This happens to be a variable that is already created for us to make our lives easier. We don't have to create it ourselves, we can simply look up the variable name and put it to use. In fact, there are a variety of built-in time and date variables, depending on how we want to format that information.

Consult the Variables page of the wiki to see a full list of built-in variables.

Other ways to find variable names

When you are building your commands in the macro builder (LCB), there are several tools to help you find the variable you're looking for:

* When entering values in relevant fields, the auto-complete will show a list of common variables when you start by typing "{"
* The parameter helper tool in the LCB also gives you access to variable names.
* If you look up action descriptions, the descriptions explain what variables are relevant for the action you are trying to use.

Commonly encountered variables

You can learn more about these and other variables by using the program, looking at existing commands in your configuration, consulting the wiki, and watching various video tutorials.

*{LastResult}
*{PF.1},{PF.2}, etc.
*{Match.1}, {Match.2} etc.
* {#M}, {#P}
*{1},{2}, etc. (Technically, these symbolize "payloads", not variables. There is an important distinction, but the notation in your command is similar so I include the reference here.)

Here's a fun built-in variable

Did you know there's a variable in VC that serves as a random number generator? (integers only!)

{Rnd.1.100} will return a random integer value between 1 and 100. You choose the number range.

Create your own variable

The action Results.SetVar allows you to create your own variable name and pass it a value, which you can then use globally -- not only in that specific command, but any command.

This means you should be careful not to use the same variable name to represent different things in different commands!

Your custom variable can then be accessed as {var.yourvarname}

These variable values are volatile and are stored only as long as VC is running. If you wish to store an enduring value (e.g. an API key or IR code), you can store that information in a map table and access it using map variables.

Plugins

Note that some of the plugins also use their own special variables. These are not listed on the main variables page of the wiki, but they are documented in the plugin's action descriptions within VoxCommando, and elsewhere in the wiki documentation.

In Sum

Variables store information that can change over time, based on changing conditions.

  • The {ShortTime} value changes because time moves on.
  • {LastSpoken} will always return the text of the most recently recognized speech.

You might find it helpful to think of {curlybrackets} as a placeholder in your command macro. {curlybrackets} will be replaced with the information that we ask VC to retrieve at that given point in time.

In other words, the value can vary depending on the conditions we set and what we ask VC to do. ("Ahhh. Variable -- I get it now." ;-p)
« Last Edit: April 21, 2017, 04:49:37 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Nodo

  • Jr. Member
  • **
  • Posts: 22
  • Karma: 6
    • View Profile
Great explanation, nime5ter. Thank you :)

I was wondering how to get a variable from within a python file. I assumed (I might be wrong) that I should use
Code: [Select]
vc.getObject("Var.Example","") I also tried omitting "Var." but I can`t get it to work. Obviously I am doing something wrong.

 

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
I was wondering how to get a variable from within a python file.

Hm. Your question could be interpreted one of two ways, so I'll start with "It depends." :)

If you've defined a variable in a python script that you then want to access in a VC macro, we have a Python action PY.GetVar. But based on your subsequent sentence, I suspect you're asking how you can use a variable defined in VC in your Python script, is that right?

The usual way is to define a Python function, and then we can pass the variable value as a parameter. http://voxcommando.com/forum/index.php?topic=1548.msg13508#msg13508

If that doesn't help, let me know what you're trying to do and I can be more specific.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Nodo

  • Jr. Member
  • **
  • Posts: 22
  • Karma: 6
    • View Profile
Thank you nime5ter. Somehow passing a variable as a parameter totally slipped my mind. I guess multi-tasking, working long hours and coffee are a bad combination :).

Thank you again for being a great help.


Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Note that some of the plugins also use their own special variables. These are not listed on the main variables page of the wiki, but they are documented in the plugin's action descriptions within VoxCommando, and elsewhere in the wiki documentation.

I think it will be nice to have a page in the wiki that list all variables ... including the ones for plug-ins ... seeing them might be inspiration for solutions and /or new commands
When Voice command gets tough, use hand gestures

JonPeyton

  • $upporter
  • Jr. Member
  • *****
  • Posts: 36
  • Karma: 3
    • View Profile
Re: NEW USERS: Variables in VoxCommando --> cool things in {curly brackets}
« Reply #5 on: December 04, 2015, 08:30:34 PM »
Thanks for this.
I have extensive ewxperience using variables in tasker but I was struggling here until I found your post.
Thanks so much! ;D

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: NEW USERS: Variables in VoxCommando --> cool things in {curly brackets}
« Reply #6 on: December 04, 2015, 09:32:56 PM »
Glad to know it's of use. Cheers.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)