VoxCommando

New Features and Feature Requests => Feature Requests => Topic started by: Haddood on October 19, 2016, 01:49:12 AM

Title: arithmatic operation inside commands
Post by: Haddood on October 19, 2016, 01:49:12 AM
James,

since it has been very long time since my last feature request :8 .. I was wondering if is it feasible to provide some simple arithmetic operations within the commands just like we could use maps and variables... i.e. say we can

if A<B , {arth. 3 + 5/2} , {arth.{var.a} + 5 * {var.b}}

support for basic function + - * / will be ample start

this will be awesome simplify lots of commands

P.S. it will be great xmas gift for all voxteers !!!
Title: Re: arithmatic operation inside commands
Post by: Kalle on October 19, 2016, 04:25:22 AM
Hi Haddood,


so far I know is this already possible with the python plugin in VoxCommando.  ::hmm


http://voxcommando.com/mediawiki/index.php?title=Python#Returning_a_Result
Title: Re: arithmatic operation inside commands
Post by: nime5ter on October 19, 2016, 08:38:36 AM
Based on your example, I think you mean that you want to be able do calculations within individual parameters in an action, as opposed to within a command.

James says he may implement your suggestion in the future for user convenience. In the meantime, you can do this now using one line of Python within a command (PY.ExecString).

Per your example:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.2.7-->
<command id="66" name="evaluate my arithmetic in this command" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>a</param>
      <param>{1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>b</param>
      <param>{2}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>PY.ExecString</cmdType>
    <params>
      <param>result =  (3 + 5.0/2) &lt;  ({var.a} + 5.0*{var.b})</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)==(B)</ifType>
    <ifParams>{LastResult}&amp;&amp;True</ifParams>
    <then>
      <action>
        <cmdType>OSD.ShowText</cmdType>
        <params>
          <param>Last result is: {LastResult}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else>
      <action>
        <cmdType>OSD.ShowText</cmdType>
        <params>
          <param>Last result is: {LastResult}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <phrase>test your own var values as payloads</phrase>
</command>

You can test different {var.a} and {var.b} values by entering different numbers in the test fields for payload 1 and 2 in the LCB.
Title: Re: arithmatic operation inside commands
Post by: Haddood on October 19, 2016, 06:46:25 PM
do calculations within individual parameters in an action, as opposed to within a command.

this is exactly what I meant :D ... kind of arithmetic on the fly as opposed to create commands to get the results in variables
Title: Re: arithmatic operation inside commands
Post by: nime5ter on October 19, 2016, 07:19:04 PM
:) Your idea will probably be helpful to many.

But we don't currently have to create separate commands. Often we can just do the arithmetic using a single Python action within our command. (At least, I haven't personally run into a scenario involving basic calculations that required creating a separate command.)