Author Topic: Use another sound if an error  (Read 4863 times)

Akoa0013

  • Newbie
  • *
  • Posts: 10
Use another sound if an error
« on: January 05, 2017, 08:46:18 AM »
So if I tell VoiceAttack to Open Steam for instance. It'll say "Steam is now available"
But if my external hard drive is not connected and an error occurs on VoiceAttack. How do I get it to say "Steam was unable to open"?

* by 'say' I use wav files for a sound response.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Use another sound if an error
« Reply #1 on: January 05, 2017, 10:56:35 AM »
The simplest way would be to check whether the process exists after you try to start it, but because there is currently no "{PROCESSEXISTS:}" token,  and that method would require a time delay, I've used a tiny snippet of C# to catch the error, if it occurs:
Code: [Select]
Set Text [~ApplicationToStart] to 'mspaint.exe'
Inline C# Function: , wait until execution finishes
Begin Boolean Compare : [~ExecutionError] Equals True
    Say, 'Error while starting application'
Else
    Say, 'Application Started'
End Condition
All you should have to do is set "~ApplicationToStart" to the location of your steam executable, and change the "Say Something with Text-To-Speech" actions into "Play a Sound" actions.

The command is attached below so you can import it.


The inline function contains:
Code: [Select]
public void main()
{
    try
    {
        System.Diagnostics.Process.Start(VA.GetText("~ApplicationToStart"));
    }
    catch(Exception e)
    {
        //VA.WriteToLog(e.ToString(),"red");//Uncomment this if you want the error to show up in the log
        VA.SetBoolean("~ExecutionError",true);
    }
}
You don't have to worry about this, but I'm including it in case anyone's curious.

Akoa0013

  • Newbie
  • *
  • Posts: 10
Re: Use another sound if an error
« Reply #2 on: January 06, 2017, 02:15:13 PM »
Do I need to install a plug-in for the "Inline C# Function"?
I get :

Error loading profile data.
[There is an error in XML document (56,12).]
Instance validation error: "InlineFunctionCS' is not a valid value for ActionTypeEnum.

When I try to import the profile you've uploaded here.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Use another sound if an error
« Reply #3 on: January 06, 2017, 02:20:15 PM »
You need beta v1.6.1.10 or later for it to work.

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: Use another sound if an error
« Reply #4 on: December 15, 2017, 11:01:19 AM »
Old thread, but I figured I'd include this information in case it may still be helpful. Check out this post for a method to check if a given process is running.