Author Topic: Command execution priority  (Read 2540 times)

jcdick1

  • Jr. Member
  • **
  • Posts: 55
Command execution priority
« on: February 01, 2021, 02:17:17 PM »
I have two events in my profile, one of which runs regularly, and one which runs occasionally.  Sometimes that "occasion" causes them to trigger simultaneously, and so the TTS responses overlap.

I apparently can't use {CMDACTIVE:name} in a compare directly (can't use colons in the field) to see if the occasional event is running, in order to "prioritize" the two and ensure that the occasional one runs first if there's an overlap, but ensure that the regular one still runs. 

Would I need to do a conversion to an integer value, then do the compare?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Command execution priority
« Reply #1 on: February 01, 2021, 02:19:48 PM »
Tokens are and return text, even if that text happens to consist of characters representing an integer number...

Use the "Text" tab of the condition action, and compare against the literal text "1" or "0".

jcdick1

  • Jr. Member
  • **
  • Posts: 55
Re: Command execution priority
« Reply #2 on: February 06, 2021, 02:54:24 PM »
I got it acknowledging the value of the variable, thanks for that.

Unfortunately, it is still setting as 0 even though the "occasional" event is still speaking, and so I'll have to figure out some other way of queuing the two.

Thanks for the help, though!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Command execution priority
« Reply #3 on: February 06, 2021, 03:03:52 PM »
What variable? Tokens are not variables, as this topic attempts to explain: Variables and tokens summed up


Do you have the "Wait until speech completes before continuing command" option checked for the "Say Something with Text-To-Speech" action(s) in the command you are checking?
If not, the command can end while the TTS audio is still playing.


Note that there are literal command queues you can utilize. Press F1 while VoiceAttack has focus to open VoiceAttackHelp.pdf in your default PDF viewer, and search for "'Command Queues - Enqueue Command'" (the "'Command Queues - Queue Action'" section below it is also relevant)

jcdick1

  • Jr. Member
  • **
  • Posts: 55
Re: Command execution priority
« Reply #4 on: February 06, 2021, 04:04:15 PM »
I had thought about the "enqueue command" but the documentation implies that a command is added to the command queue at time of execution of the command using the "enqueue command" action as a first step.  My hesitation with that is that since these two non-spoken commands are triggered by the same event, if I add the "enqueue command" to each of them, what happens if the one I want to go second - on those occasions that they do overlap - triggers just a millisecond before the other due to CPU load or the like?  Wouldn't it end up in the command queue ahead of the other?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Command execution priority
« Reply #5 on: February 06, 2021, 04:11:55 PM »
A command cannot enqueue itself (to prevent infinite looping), so you'd want to set up a separate command triggered by the event to use two "Enqueue Command" actions in sequence, which should guarantee the order of execution.

Do they trigger off the same event though? In your first post you instead stated that you had "two events" in your profile.
Accurate and adequate information is necessary to gain an understanding of the situation.

jcdick1

  • Jr. Member
  • **
  • Posts: 55
Re: Command execution priority
« Reply #6 on: February 06, 2021, 04:29:28 PM »
Quote
Do they trigger off the same event though?

Well, yes and no?  I mean, one is the "System scan complete" event from EDDI that triggers when scanning the last scannable body in a system in E:D.  The other is a response to the "Body scanned" event from EDDI that may or may not be triggered when also scanning the last scannable body, depending on the characteristics of that body.

On the occasion that the two trigger at the same time, I'd like that "body scanned" response to go first, then the "system scan complete" response.  But the "body scanned" response may only occur 10% of the time.

If I create a special non-spoken command with the two "enqueue command" entries, will it still run the "body scanned" as part of the queue even if its not valid?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Command execution priority
« Reply #7 on: February 06, 2021, 04:57:36 PM »
If I create a special non-spoken command with the two "enqueue command" entries, will it still run the "body scanned" as part of the queue even if its not valid?
Unless your commands have conditions in them that would prevent them from executing, yes.


In this type of race condition (where two events "race" against each other, and either may come in first), you may be best off using a delay, to make sure that if both events are to occur, they have occurred by the time the second command executes.

This could combined with the "{CMDACTIVE:}" token you were already using to form a waiting loop.
E.G.
Code: [Select]
Pause 0,1 seconds
Start Loop While : [{CMDACTIVE:Body scanned}] Equals '1'
End Loop
Say, 'System scan complete'
The pause would need to be long enough to allow both events to occur, but only the second command (I.E. "System scan complete") would need to wait like this.


Command queues execute commands in the order they were added (first in, first out), but that does rely on you being able to add them in that order.
You could replace the waiting loop with an enqueuing action, however that would require additional commands.

The queuing system would be most useful if you anticipate additional text-to-speech commands that may be triggered while these two are speaking in turn, so that you can queue the additional ones as well.
Otherwise using a waiting loop may be the simplest option.

jcdick1

  • Jr. Member
  • **
  • Posts: 55
Re: Command execution priority
« Reply #8 on: February 06, 2021, 05:05:05 PM »
The While loop is what I tried to do, but it kept registering {CMDACTIVE:body scanned} as 0 and so ran "System scan complete" anyway.  I double checked it by having an opening pause, just as you have in your example, then had it write the value out and I'd check it whenever the two overlapped.  It was always 0.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Command execution priority
« Reply #9 on: February 06, 2021, 05:09:33 PM »
Did you have the "Wait until speech completes before continuing command" option checked for the "Say Something with Text-To-Speech" action at the time?

As mentioned, that is necessary in order for the command to register as "active", as otherwise the action will run asynchronously, and the command can finish executing while the audio is still being played back.