Author Topic: Using maps to replace multiple ifs  (Read 2993 times)

0 Members and 1 Guest are viewing this topic.

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Using maps to replace multiple ifs
« on: March 27, 2015, 06:58:38 PM »
now and then I face a command where I need many ifs (to simulate a switch command) ... and the command does not look efficient ...
today I had this idea to make this very simple. By replace the multiple ifs with values from a map ....
images explain it all ...

for sure for 3 ifs is not a big deal, apart from being neat ... but in case of 50, this will be a big difference

« Last Edit: March 27, 2015, 07:00:57 PM by Haddood »
When Voice command gets tough, use hand gestures

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Using maps to replace multiple ifs
« Reply #1 on: March 27, 2015, 07:33:12 PM »
That does seem more efficient. :)

Actually in the case of that example, you could even do it in a single line:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.2-->
<command id="587" name="one line" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>PY.ExecString</cmdType>
    <params>
      <param>LEDcolour("{M:Mapping.LED{status}}")</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
</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)

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: Using maps to replace multiple ifs
« Reply #2 on: March 27, 2015, 08:37:36 PM »
Wow ... Now I have to go check all my commands :)
When Voice command gets tough, use hand gestures