VoxCommando

Help and Support (Using VoxCommando) => Tutorials => Topic started by: nime5ter on May 01, 2015, 10:53:26 AM

Title: NEW USERS: Variables in VoxCommando --> cool things in {curly brackets}
Post by: nime5ter on May 01, 2015, 10:53:26 AM
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 (http://voxcommando.com/mediawiki/index.php?title=Variables) 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 (http://voxcommando.com/mediawiki/index.php?title=Logical_Command_Builder)), 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 (http://voxcommando.com/mediawiki/index.php?title=Parameter_Helper) in the LCB also gives you access to variable names.
* If you look up action descriptions (http://voxcommando.com/mediawiki/index.php?title=Action_Selection_Tree), 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. (http://voxcommando.com/forum/index.php?topic=1681.0)
*{Match.1}, {Match.2} etc.
* {#M}, {#P}
*{1},{2}, etc. (http://voxcommando.com/forum/index.php?topic=1681.0) (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 (http://voxcommando.com/mediawiki/index.php?title=Actions#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 (http://voxcommando.com/mediawiki/index.php?title=Maps) 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.


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)
Title: Re: NEW USERS: Variables in VoxCommando --> cool things in {curly brackets}
Post by: Nodo on June 16, 2015, 05:23:38 PM
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.

 
Title: Re: NEW USERS: Variables in VoxCommando --> cool things in {curly brackets}
Post by: nime5ter on June 16, 2015, 06:24:40 PM
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.
Title: Re: NEW USERS: Variables in VoxCommando --> cool things in {curly brackets}
Post by: Nodo on June 17, 2015, 07:47:53 PM
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.

Title: Re: NEW USERS: Variables in VoxCommando --> cool things in {curly brackets}
Post by: Haddood on June 17, 2015, 07:54:56 PM
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
Title: Re: NEW USERS: Variables in VoxCommando --> cool things in {curly brackets}
Post by: JonPeyton 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
Title: Re: NEW USERS: Variables in VoxCommando --> cool things in {curly brackets}
Post by: nime5ter on December 04, 2015, 09:32:56 PM
Glad to know it's of use. Cheers.