Author Topic: running a command until condition is met  (Read 4018 times)

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
running a command until condition is met
« on: May 10, 2020, 01:41:38 PM »
would I be correct that a loop inside a condition block could have it loop until the condition is met.

Example having the command execute a jump command but has to wait until the ship is not mass locked.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: running a command until condition is met
« Reply #1 on: May 10, 2020, 01:55:52 PM »
While loop actions already contain a "condition", which they will evaluate every iteration, I.E. before and after the actions within it have been executed (or, if there are no actions to execute, every few milliseconds).

Placing a loop within a separate condition block is likely redundant if you're using the loop to have the command wait.

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: running a command until condition is met
« Reply #2 on: May 11, 2020, 12:06:05 PM »
I have tried to get it to work, not sure what I am missing or maybe I am misunderstanding what you were telling me.

Set text [statusFlags] to [C:\Users\PcGamer\Saved Games\Frontier Developments\Elite Dangerous\Status.json]
Inline C# Function: , wait until execution finishes
Begin Text Compare : [statusFlags] Contains 'HudInAnalysisMode'
    Execute command, 'Switch modes' (and wait until it completes)
End Condition
Begin Text Compare : [statusFlags] Contains 'LandingGearDown'
    Execute command, 'Landing Gear - Keybinding' (and wait until it completes)
End Condition
Begin Text Compare : [statusFlags] Contains 'CargoScoopDeployed'
    Execute command, 'Cargo Scoop - Keybinding' (and wait until it completes)
End Condition
Begin Text Compare : [statusFlags] Contains 'HardpointsDeployed'
    Execute command, 'Hardpoints - Input Key - Keybinding' (and wait until it completes)
End Condition
Begin Text Compare : [statusFlags] Does Not Contain 'FsdMassLocked'
    Say, 'enable fsd'
End Condition - Exit when condition met

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: running a command until condition is met
« Reply #3 on: May 11, 2020, 12:11:19 PM »
...there is no loop action in your command, so what exactly are you expecting to happen?

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: running a command until condition is met
« Reply #4 on: May 11, 2020, 12:15:39 PM »
Ok I did misunderstand you I thought you said these commands had an loop command built in.
I did also try it with a loop command but it did not work either, so if I put a loop command inside the condition block that should get the result I want?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: running a command until condition is met
« Reply #5 on: May 11, 2020, 12:33:12 PM »
No, I stated
While loop actions already contain a "condition"
I.E. the "Loop Start" action for a while loop evaluates a condition, as configured when you added the action; That is how any while loop functions (it loops while a statement evaluates to true).


Think through what occurs when your command executes, and how each action affects the state of your variables.
Placing a loop inside any of the conditions inside the command you've posted will result in the command looping indefinitely, because the values are only set at the start of the command.

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: running a command until condition is met
« Reply #6 on: May 11, 2020, 09:22:08 PM »
Ok I have spent several hours on trying to figure out where and how the loop should be used with the below command.
I need some help here what am I doing wrong. BTW this is the last of a long list of different locations for the loop command. I can get to print on one part of the command infinitely but not both and I can get it to not work at all.

Begin Text Compare : [statusFlags] Contains 'FsdMassLocked'
    Write 'TXT:full power' to log
End Condition
Start Loop : Repeat 1000 Times
    Begin Text Compare : [statusFlags] Does Not Contain 'FsdMassLocked'
    End Loop
    Write 'Txt:Enable FSD' to log
End Condition

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: running a command until condition is met
« Reply #7 on: May 12, 2020, 05:14:43 AM »
Placing a loop inside any of the conditions inside the command you've posted will result in the command looping indefinitely, because the values are only set at the start of the command.

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: running a command until condition is met
« Reply #8 on: May 12, 2020, 01:07:43 PM »
I clearly am not understand what you are trying to tell me. I tried putting the loop command around the conditional block, in the conditional block and below the conditional block, none of the seemed to work,  So I tried to simplify it for me and ended up trying this

Begin Text Compare : [statusFlags] Contains 'FsdMassLocked'
    Write 'TXTfull power' to log
End Condition
Pause 10 seconds
Begin Text Compare : [statusFlags] Does Not Contain 'FsdMassLocked'
    Write 'Txt:Enable FSD' to log
End Condition

This did not work either.

I am trying and have read what I could find on line about where and how to use loops, but even that was above my experience level.
I feel I am just wasting your time, you giving me hints as to what I am doing wrong, but even those hints are above me it would appear, I think I do not know enough about the programing language to even understand what I am told.
I have found something Exergist posted "Wait for process window to activate", to see of an example of how it is used, but that just brought me to a full stop confused.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: running a command until condition is met
« Reply #9 on: May 12, 2020, 01:30:11 PM »
You are setting a variable value using an inline function at the start of your command, and only at the start of your command; When you use that variable further down in your command, it'll still have the same value you set at the start, so there's no sense in checking that value in multiple times, as you should know it cannot have changed in the mean time.

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: running a command until condition is met
« Reply #10 on: May 12, 2020, 03:40:58 PM »
Well after you spelled it out for me I got what you were saying and what I was leaving out, but no matter where I put the loop command it does not seem to work. How ever I was able to get it to work with a pause command. I was hoping to use the loop as a pause until the change in conditions was met, but I just can't figure out the loop command and where it goes.

Set text [statusFlags] to [C:\Users\PcGamer\Saved Games\Frontier Developments\Elite Dangerous\Status.json]
Inline C# Function: , wait until execution finishes
Begin Text Compare : [statusFlags] Contains 'HudInAnalysisMode'
    Execute command, 'Switch modes' (and wait until it completes)
End Condition
Begin Text Compare : [statusFlags] Contains 'LandingGearDown'
    Execute command, 'Landing Gear - Keybinding' (and wait until it completes)
End Condition
Begin Text Compare : [statusFlags] Contains 'CargoScoopDeployed'
    Execute command, 'Cargo Scoop - Keybinding' (and wait until it completes)
End Condition
Begin Text Compare : [statusFlags] Contains 'HardpointsDeployed'
    Execute command, 'Hardpoints - Input Key - Keybinding' (and wait until it completes)
End Condition
Begin Text Compare : [statusFlags] Contains 'FsdMassLocked'
    Write 'TXTfull power' to log
End Condition
Pause 10 seconds
Set text [statusFlags] to [C:\Users\PcGamer\Saved Games\Frontier Developments\Elite Dangerous\Status.json]
Inline C# Function: , wait until execution finishes
Begin Text Compare : [statusFlags] Does Not Contain 'FsdMassLocked'
    Write 'TXTCharging drive' to log
End Condition

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: running a command until condition is met
« Reply #11 on: May 12, 2020, 03:43:38 PM »
The issue remains the same: You need to update the value of the variable before checking it again, I.E. every iteration of your loop.

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: running a command until condition is met
« Reply #12 on: May 12, 2020, 03:56:00 PM »
So in the above command is the pause giving it time to update
 and that is why it works? Where when I use to loop command there is no pause so its not allowing it to update?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: running a command until condition is met
« Reply #13 on: May 12, 2020, 04:11:32 PM »
If you configure your while loop correctly, it will wait until the value changes.

You need to set it up so it loops while the variable does not have the value you're looking for, and make sure the variable value is updated within the loop, so that when the loop comes around the value will have been updated before it is checked again.


You cannot expect to put together advanced commands without understanding what you're doing. Blind trial and error is not the way to go about this.

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: running a command until condition is met
« Reply #14 on: May 12, 2020, 04:16:41 PM »
Yep I can see that so I guess I should just wait until I get more experience at this, and use what I can make work.
Thanks.

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: running a command until condition is met
« Reply #15 on: May 12, 2020, 08:06:29 PM »
I was poking around the internet and ran across this guy who is very informative and explained Loops, else, and elseif, in a way I almost could under stand it even had examples. It was a little on the old side. I was wondering you could convince him to update it.
here is the link,
https://forum.voiceattack.com/smf/index.php?topic=732.0

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: running a command until condition is met
« Reply #16 on: May 12, 2020, 08:10:53 PM »
Update what, exactly? All the information in that topic applies to currently available actions, that haven't changed since it was written.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: running a command until condition is met
« Reply #17 on: May 12, 2020, 09:03:38 PM »
Yup - that is the currently-used example and is what where we direct folks that need a primer on how to do that kind of stuff.  Actually, quite a good example.

Gangrel

  • Caffeine Fulled Mod
  • Global Moderator
  • Full Member
  • *****
  • Posts: 216
  • BORK FNORK BORD
Re: running a command until condition is met
« Reply #18 on: May 13, 2020, 03:00:30 AM »
I was poking around the internet and ran across this guy who is very informative and explained Loops, else, and elseif, in a way I almost could under stand it even had examples. It was a little on the old side. I was wondering you could convince him to update it.
here is the link,
https://forum.voiceattack.com/smf/index.php?topic=732.0

Funnily enough, the person who would need convincing is the exact same person who is helping you right now.

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: running a command until condition is met
« Reply #19 on: May 13, 2020, 01:34:04 PM »
Yes I am someone that can't let many things go until I figure it out and I want to Thank you Pfeil for your patients I know  it can be difficult giving advice to people that don't really know what they are doing but you help advice and the write up you did helped me figure it out hopefully.

Ok it seems to work and if I did it right do I still need the pause?

Begin Text Compare : [statusFlags] Contains 'FsdMassLocked'
    Write 'TXTfull power' to log
Else
    Execute command, 'Enable Frameshift Drive - Keybinding' (and wait until it completes)
End Condition
Pause 5 seconds
Set text [statusFlags] to [C:\Users\PcGamer\Saved Games\Frontier Developments\Elite Dangerous\Status.json]
Start Loop While : [statusFlags] Does Not Contain 'FsdMassLocked'
    Inline C# Function: , wait until execution finishes
End Loop
Write 'TXTCharging drive' to log


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: running a command until condition is met
« Reply #20 on: May 13, 2020, 01:40:01 PM »
That will not work correctly, as the data you're passing to the inline function is not updated within the loop.

If it is updated within the loop, the pause is not strictly necessary (though I would still add a short pause to the loop itself to reduce resource usage, say 100ms so, unless you absolutely need the fastest possible response time to the value changing).

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: running a command until condition is met
« Reply #21 on: May 13, 2020, 01:42:10 PM »
So yep wrong again, I am not winning this battle


Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: running a command until condition is met
« Reply #22 on: May 13, 2020, 05:23:55 PM »
Ok I think I have the loop trying to update, but I am receiving an error saying that another process is using it. Any hints?

4:17:58.446 Error getting status flags: '"Flags:"' section not found
4:17:58.417 Unable to get value from URI - The process cannot access the file 'C:\Users\PcGamer\Saved Games\Frontier Developments\Elite Dangerous\Status.json' because it is being used by another process.

Set text [statusFlags] to [C:\Users\PcGamer\Saved Games\Frontier Developments\Elite Dangerous\Status.json]
Inline C# Function: , wait until execution finishes
Begin Text Compare : [statusFlags] Contains 'HudInAnalysisMode'
    Execute command, 'Switch modes' (and wait until it completes)
End Condition
Begin Text Compare : [statusFlags] Contains 'LandingGearDown'
    Execute command, 'Landing Gear - Keybinding' (and wait until it completes)
End Condition
Begin Text Compare : [statusFlags] Contains 'CargoScoopDeployed'
    Execute command, 'Cargo Scoop - Keybinding' (and wait until it completes)
End Condition
Begin Text Compare : [statusFlags] Contains 'HardpointsDeployed'
    Execute command, 'Hardpoints - Input Key - Keybinding' (and wait until it completes)
End Condition
Begin Text Compare : [statusFlags] Contains 'FsdMassLocked'
    Write 'TXTfull power' to log
End Condition
Start Loop While : [statusFlags] Contains 'FsdMassLocked'
    Set text [statusFlags] to [C:\Users\PcGamer\Saved Games\Frontier Developments\Elite Dangerous\Status.json]
    Inline C# Function: , wait until execution finishes
    Begin Text Compare : [statusFlags] Does Not Contain 'FsdMassLocked'
    End Condition
End Loop
Write 'TXTCharging drive' to log



Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: running a command until condition is met
« Reply #23 on: May 13, 2020, 05:28:04 PM »
That's another reason to add a delay to your loop. The file cannot be read while it's being written, and the more often you attempt to read it, the bigger the chance there will be a read attempt while it's in use.

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: running a command until condition is met
« Reply #24 on: May 13, 2020, 05:44:06 PM »
So it is being written to when I get that error, that would also explain why it randomly worked. I will start with a one second pause and move up from there

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: running a command until condition is met
« Reply #25 on: May 14, 2020, 10:14:27 PM »
this is what I ended up with it does work but I am still messing with the pause so I don't get an error while the file is updating
Thanks
FYI the Zero speed is so I don't run into the star when I am not paying attention when I come out of FSD