Author Topic: arithmatic operation inside commands  (Read 2376 times)

0 Members and 1 Guest are viewing this topic.

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
arithmatic operation inside commands
« 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 !!!
« Last Edit: October 19, 2016, 01:54:13 AM by Haddood »
When Voice command gets tough, use hand gestures

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2320
  • Karma: 47
    • View Profile
Re: arithmatic operation inside commands
« Reply #1 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
***********  get excited and make things  **********

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: arithmatic operation inside commands
« Reply #2 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.
« Last Edit: October 19, 2016, 05:42:14 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)

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: arithmatic operation inside commands
« Reply #3 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
When Voice command gets tough, use hand gestures

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: arithmatic operation inside commands
« Reply #4 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.)
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)