Author Topic: Only running a command once  (Read 1507 times)

Peter Dulong

  • Newbie
  • *
  • Posts: 31
Only running a command once
« on: March 15, 2021, 02:49:00 PM »
I'm stuck on this..in my profile I have several commands that I don't want to execute once they have been started. So for example: If I say "start the game" it starts up a certain game. I don't want that command to be able to execute again. until I exit the profile. So you can only say that command one time. if I try to execute it again..i want it to tell me it's already running.

I'm not sure how to do this.


Peter

jonsky7

  • Newbie
  • *
  • Posts: 14
Re: Only running a command once
« Reply #1 on: March 15, 2021, 04:03:46 PM »
You could set up "true/false booleans" for example

Code: [Select]
when I say - Start Call of Duty
Begin Boolean Compare : [CODrun] Equals False
    Run application 'G:\Call of Duty\CoD Modern Warfare 2019\Call of Duty Modern Warfare\ModernWarfare.exe'
    Set Boolean [CODRun] to True
Else If Boolean Compare : [CODrun] Equals True
    Say, 'game is running'
    Exit Command
End Condition

You would also have to setup a command that runs when the profile starts that included
Code: [Select]
Set Boolean [CODRun] to false
I'm not an expert, but I think that would work

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Only running a command once
« Reply #2 on: March 15, 2021, 04:25:03 PM »
Setting a variable is one option, though rather than using another command to reset that, you can make it profile-scoped (add a ">" symbol to the beginning of your variable name, E.G. ">CODRun"), so that it'll be reset once you unload the profile, automatically.

Press F1 while VoiceAttack has focus to open VoiceAttackHelp.pdf in your default PDF viewer, and see the "Advanced Variable Control (Scope and Events)" section for more information.


That said, if you specifically want to make sure an application isn't started twice, you could instead check whether the application is already running, either based on whether a given window exists (using the "{WINDOWEXISTS:}" token), or whether a process exists (using the "{PROCESSEXISTS:}" token).

E.G. something like
Code: [Select]
Set text [~targetProcess] to 'ModernWarfare'
Begin Text Compare : [{PROCESSEXISTS:~targetProcess}] Equals '1'
    Write [Orange] 'Process "{TXT:~targetProcess}" already running; command cancelled)' to log
End Condition - Exit when condition met

At the top of your command

These topics may be of use, in addition to VoiceAttackHelp.pdf, if you're not yet familiar with those concepts:
Control flow (If, Else, ElseIf, Loop, Jump) basics
Variables and tokens summed up

Peter Dulong

  • Newbie
  • *
  • Posts: 31
Re: Only running a command once
« Reply #3 on: March 15, 2021, 05:02:48 PM »
OMG you got it. thank you so much, that works like a charm.

Peter

Peter Dulong

  • Newbie
  • *
  • Posts: 31
Re: Only running a command once
« Reply #4 on: March 15, 2021, 05:22:28 PM »
Is there a command to stop existing commands that you have already launched...So I can only launch them once. .not Processes or Windows, but internal commands. if that makes any sences


Peter

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Only running a command once
« Reply #5 on: March 15, 2021, 06:41:21 PM »
Do you mean stopping a command that's already running, so you can start a new instance of it?

The "Stop Another Command" action can stop a given command, however it will stop all instances of that command, so if you use it in the command you're stopping, the command will stop itself as well.

To get around that, you'd need to use a "launcher" command, which then in turn starts another command that actually does the work, so that the "launcher" command can stop all instances of the worker command, before launching a new instance of the worker command.


Otherwise, if you just want to make sure only one instance of a command is running at a time (while still allowing the command to be used multiple times, just not simultaneously), you can use the "Do not execute this command if it is already running" option (found by clicking the "Advanced" button)