Author Topic: I'm having a problem, and wondering if a loop would help, Don't know how though.  (Read 9536 times)

iceblast

  • Sr. Member
  • ****
  • Posts: 372
I have a problem, I'm using auto repeat for a command, and it seems to make things a bit unstable after awhile, and I'm wondering if looping is a better way to do it. The only problem is, I can't seem to get looping to work. Clearly, I have no idea what I'm doing.

So, I was wondering, if someone could upload a basic looping Vap, and a advanced one, showing the more complicated things you can do with it.

Right now, I have like 5 blocks, Beginning block, 4 if else blocks, and end block on repeat. No idea the correct way to use a loop for this.

I've attached a picture, The end block didn't fit in the window, but it's there.

I could really use the help, if anyone is willing.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
I'm using auto repeat for a command, and it seems to make things a bit unstable after awhile, and I'm wondering if looping is a better way to do it.
Loop or not, add a pause to the end of your command; Currently, you're running the command every 3 milliseconds, which may not be the root cause of your issue, but is unnecessary nonetheless.

Also, if you were to accidentally hit the tilde(~) key, you'd have another of these commands running, which will compound the problem.

So, I was wondering, if someone could upload a basic looping Vap, and a advanced one, showing the more complicated things you can do with it.
There are two basic types of "loop" currently implemented as actions within VoiceAttack: A while loop, and a jump.

The while loop will evaluate a statement every time it loops, and continues looping as long as that statement is true.

E.G.
Code: [Select]
Set small int (condition) [Counter] value to 3
Start Loop While : [Counter] Is Greater Than Or Equals 0
Write '[Blue] {SMALL:Counter}' to log
Set small int (condition) [Counter] value as decremented by 1
Pause 1 second
End Loop
Will count down from 3 to 0 and stop as soon as "Counter" goes below 0(-1).

If desired, you can have it running infinitely by providing a value that will always be true, E.G.
Code: [Select]
Start Loop While : [{EXP:1=1}] Equals '1'
Write '[Purple] This is a quasi-infinite loop
End Loop
Now, it may be tempting to just skip {EXP:} and use
Code: [Select]
Start Loop While : [x] Has Not Been Set
End Loop
However, you cannot guarantee that said value will never be set, for example by a downloaded profile, so I cannot recommend using this(You could argue from a certain length it's unlikely that the variable will exist, but I'd rather avoid the possibility altogether).


The jump on the other hand is in a way a "purer" form of a loop; It's pretty much how a loop works internally.
Code: [Select]
Marker: Loop
Write '[Purple] This is also a somewhat infinite loop' to log
Jump to Marker: Loop

As an aside, a jump can also be used for a while loop:
Code: [Select]
Marker: Loop
Begin Text Compare : [{EXP:1=1}] Equals '1'
    Write '[Purple] This loop could run infinitely, but due to the realities of the universe, that is unlikely.' to log
    Jump to Marker: Loop
End Condition
Though there's no reason for it, now that there's a built-in action for it.

Either way, the main thing to remember when using jump markers is that they must have a unique name within the command(not the profile), in case you're using multiple jumps.


Background aside, I'd do it this way:

Start Auto Switcher
Code: [Select]
Kill command, 'call me'
Execute command, 'call me'

Auto Switcher
Code: [Select]
Start Loop While : [{EXP:1=1}] Equals '1'
    Begin Text Compare : [{ACTIVEWINDOWTITLE}] Contains 'Blaste - Opera'
        Set small int (condition) [Window] value to 2
    Else
        Set small int (condition) [Window] value to 1
    End Condition
    Begin Text Compare : [{ACTIVEWINDOWTITLE}] Contains 'Zoom Player'
        Change to profile, 'Zoom Player'
    Else If Text Compare : [{ACTIVEWINDOWTITLE}] Contains 'Edit'
        Change to profile, 'CSS'
    Else If Text Compare : [{ACTIVEWINDOWTITLE}] Contains 'Total Commander'
        Disable Mouse Shortcuts
    End Condition
    Pause 1 second
End Loop

The first command needs to be separate because VoiceAttack cannot terminate a command from within itself to prevent duplicates, so you'd use that as the launcher in case you hit the key again(or want to restart it for whatever reason); If you have a command that runs when the profile loads, you could add those actions to it instead.

Aside from that, the main command is your actions, wrapped in an infinite loop, with a delay. One second should still be snappy enough when switching windows, but you can lower the time if you prefer.
« Last Edit: August 13, 2016, 03:49:10 PM by Pfeil »

iceblast

  • Sr. Member
  • ****
  • Posts: 372
Thanks a great deal for this.

A couple things though, the ~ key was just to restart for testing. When I had it running, I turned that off. So, no need for the safety launcher before the start, the moment it switches profiles, the loop ends as well.

Also, I forgot to add that I did have a 1 second pause at the end, it just wasn't in the picture.

I've added the loop, and everything seems to be working, but it took awhile for it to start acting up. So, I guess time will tell.

Just wondering, does the computer/or VA act differently when using a loop VS auto repeat? It seems like the same thing, just hoping that it isn't, and it handles better.

Again thanks for the help. It seems I've done this 3 different ways now, hopefully, this does the trick. :)

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
I did have a 1 second pause at the end
Ah. I'd hoped the delay would alleviate the problem somewhat at least, but alas.

Can you elaborate on the instability?

And how do you have the command set up across different profiles? Did you copy it over, or is it in an included profile?

Just wondering, does the computer/or VA act differently when using a loop VS auto repeat? It seems like the same thing, just hoping that it isn't, and it handles better.
That's for Gary to answer, as I have no knowledge of the underlying code.

In theory there shouldn't be a difference, aside from the inability to only loop part of the command.

iceblast

  • Sr. Member
  • ****
  • Posts: 372
> Can you elaborate on the instability?

VA would stop taking commands, other programs would glitch. I cut off VA, and restart it, and everything went back to normal. Sorry, not sure how much time passed though. I till to lose track of time easily.

> And how do you have the command set up across different profiles? Did you copy it over, or is it in an included profile?

I basically copy and paste the commands, and add or remove profiles that it will switch to. It loads the Auto Switcher command on profile start. So, it switches, and restarts the loop.

Enable Auto Profile Switcher does the same thing, but doesn't see that I switched title windows every time. I might have to switch back and forth a couple of time for it to register.

Doing it with my Auto Switcher command, works every time, with no doubt, just hope this works better with the loop vs auto repeat.

I have to use a AutoHotKey script, that strips Opera off the end of certain windows, just to get part of this command to work. Otherwise, it can't tell the difference between a windows title with Opera at the end, and a windows title that starts with Edit, but also ends with Opera. I think if you could make VA look for 2 different exact things, it would solve that problem. My point of bringing this up though was to say, AutoHotKey script isn't lagging, when it sees the windows title, it instantly changes it, so, I think that rules out my computer being the issue for the lag in Auto Profile Switching. No idea what it could be. It's not a lag though is it, it's not like I could just wait a few seconds and then it switches, it just randomly never bothers to try. No idea.

VA is constantly getting better, so, maybe in the future, this won't be a problem. :)

iceblast

  • Sr. Member
  • ****
  • Posts: 372
I had to reboot my computer. I've been running just fine all night, till I decided to edit a style.

I don't have my AHK scripts running at startup. I forgot about it. So, when I went to try to Edit a style, VA crashed. Couldn't believe it, so, I restarted it and tried again, figuring the Loop just made it unstable, and it crashed again instantly when I tried to switch to the Edit web page.

Now, without my AHK script, VA is trying to tell the difference between a window that [Ends with Opera], and another that contains [Edit], but also [Ends with Opera]. VA runs into a conflict here, and crashes. If VA could Match 2 things, then this wouldn't be a problem. No idea how hard it is to make VA do that though.

Anyway, when I run the AHK script to strip Opera off the end of my Edit windows, I don't have a problem. I'm going to have to add my AHK script to windows startup, the reason I didn't before is, I don't reboot very often. Not for the last 2 weeks, so didn't think of it.

Is there a way, to get VA to strip 8 letters off the end of a line of text? I know you can rename a window, but I just can't think of a easy way to set that up for around 30 different windows.

I'll probably let the loop run for a couple days, and if everything is good, I'll report back. It would nice, if something went right for a change.


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Now, without my AHK script, VA is trying to tell the difference between a window that [Ends with Opera], and another that contains [Edit], but also [Ends with Opera]. VA runs into a conflict here, and crashes.
That's...odd. How do you have that command structured?

If VA could Match 2 things, then this wouldn't be a problem. No idea how hard it is to make VA do that though.
It's possible through the use of "{EXP:}":
Code: [Select]
Begin Text Compare : [{EXP:{ACTIVEWINDOWTITLE LIKE '*Opera' And {ACTIVEWINDOWTITLE LIKE '*Edit*'}] Equals '1'
End Condition
This will return 1 if both are true

Is there a way, to get VA to strip 8 letters off the end of a line of text?
Again, "{EXP:}":
Code: [Select]
Begin Text Compare : [{EXP:SUBSTRING('{ACTIVEWINDOWTITLE}',1,LEN('{ACTIVEWINDOWTITLE}') - 8)}] Contains 'Edit'
End Condition
« Last Edit: August 14, 2016, 09:27:13 AM by Pfeil »

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2826
I can't get into any detail as I am traveling.

If there are issues you are experiencing with VA, please indicate each individually in the issues board.  Make sure to provide steps to reproduce the problem, as well as indicate the result you are getting versus the result you are expecting.  My apologies if you have already done this before...  I am responding from my phone ;)

iceblast

  • Sr. Member
  • ****
  • Posts: 372
Awesome! Looks like this works. I don't have to run my AHK script. Of course, I haven't used it enough yet, to be 100% yet, but looks good so far.

This is what I used.

If Windows Title Ends with Opera and Contains Edit then do whatever
{EXP:'{ACTIVEWINDOWTITLE}' LIKE '*Opera' And '{ACTIVEWINDOWTITLE}' LIKE '*Edit*'}

If Windows Title Ends with Opera But doesn't Contain Edit then do whatever
{EXP:'{ACTIVEWINDOWTITLE}' LIKE '*Opera' AND NOT '{ACTIVEWINDOWTITLE}' LIKE '*Edit*'}

This does strip Opera off the end of the Title Window.
{EXP:SUBSTRING('{ACTIVEWINDOWTITLE}',1,LEN('{ACTIVEWINDOWTITLE}') - 8)}

But it's not as easy to setup to do the job I need, as the first 2.


So, I have 2 different ways to go about solving my problem, which is nice.

I did come across a odd problem though, right away. This forum post Title is triggering the, If the Title contains [*Edit*] don't switch profiles to Main.

Here's the title: I'm having a problem, and wondering if a loop would help, Don't know how though. - Opera

I don't see Edit in the title at all, yet, it apparently does. It seems to work fine on every other window I tried it on. I even changed the word [*Edit*] to [*Edit Style*] and made no difference. Maybe you'll see something I don't.

Anyway, looks liked I learned a few new tricks which is awesome. As long as everything remains stable, I'm good to go. :)

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
I did come across a odd problem though, right away. This forum post Title is triggering the, If the Title contains [*Edit*] don't switch profiles to Main.

Here's the title: I'm having a problem, and wondering if a loop would help, Don't know how though. - Opera
It's triggering because the evaluation is returning "Expression error", which apparently evaluates as true.

This is a bug in VoiceAttack from what I can see. It's throwing errors when "'"(that's a singlequote) is used within the evaluation.


As a temporary workaround, you can remove the singlequotes:
Code: [Select]
Set Text [ACTIVEWINDOWTITLE] to '{ACTIVEWINDOWTITLE}'
Set Text [ACTIVEWINDOWTITLE] to '{TXTREPLACE:ACTIVEWINDOWTITLE:':}'
Begin Text Compare : [{EXP:'{TXT:ACTIVEWINDOWTITLE}' LIKE '*Opera' And '{TXT:ACTIVEWINDOWTITLE}' LIKE '*Edit*'}] Equals '1'
End Condition

Or, as the documentation states "This token has been deprecated and is no longer supported.":
Code: [Select]
Set Text [ACTIVEWINDOWTITLE] to '{ACTIVEWINDOWTITLE}'
Set Text [SingleQuote] to '''
Set Text [Blank] to ''
Set Text [ACTIVEWINDOWTITLE] to '{TXTREPLACEVAR:ACTIVEWINDOWTITLE:SingleQuote:Blank}'
Begin Text Compare : [{EXP:'{TXT:ACTIVEWINDOWTITLE}' LIKE '*Opera' And '{TXT:ACTIVEWINDOWTITLE}' LIKE '*Edit*'}] Equals '1'
End Condition

iceblast

  • Sr. Member
  • ****
  • Posts: 372
OK, that took awhile to figure out. Sorry, but I can be very dense when it comes to programming. I get tripped up by many things. It takes me a great deal of trial and error to find the solution. Luckily, I usually have a great deal of patience. I could ask a question, but if you ask a question that is just to stupid, people will blow you off, and there goes the help you needed.

Anyway, I learned a few things, and that is something that usually comes with trial and error.

The original issue was, you used the wrong code for the solution. Not your fault though, but since I'm a bit dense when it comes to this stuff, I missed the obvious.

This is the correct code:

{EXP:'{TXT:ACTIVEWINDOWTITLE}' LIKE '*Opera' And NOT '{TXT:ACTIVEWINDOWTITLE}' LIKE '*Edit*'}

Your code was checking if both Opera and Edit was in the title, instead of making sure that just Opera was in the title.

Again not your fault. I should have noticed, and I eventually did. :)

First I tried the first example you gave me, and didn't work, so, I tried the second. Honestly, it made my head hurt just trying to read, I had no idea what was going on it.

Tried many things, and it still didn't work. So, I figured, you did something wrong, or what you did, just wasn't working for me. So, I started trying to build it from scratch. Which meant, I had to learn what each line did, and why.

I kept trying different things, then I figured out how to send what was in the Variable to a file so I could see if it was even removing the Single Quotes or not, and since there were 2 of them, was it removing both. I had actually made the command to run twice just to get both Quotes, just in case, that was what made me try to send the Variable to a file.

The file showed, that the Quotes were gone, I even redid it, without the second removal, and it still got both Quotes. I was like great, that works, now why doesn't the whole thing work. I saw it had Comma's, so, I removed them as well. :) Nothing :) I was going to do Periods next, but I saw VA didn't have a problem with Periods.

I then made the file into a Variable . and that didn't work. Then it came to me. NOT was not in the equation. That's why it wasn't working. So, I added NOT, bam, it worked.

So, I added it to my Auto Switch command, and problem solved. Jeez :)

Anyway, I learned a lot today, and I love the feeling, when finally, everything works. Thanks for all your help.

iceblast

  • Sr. Member
  • ****
  • Posts: 372
Just a update.

Everything has been working great. Loops seem more stable. It's been pretty nice. :)

Thanks again for the help. I've used a few things from learning how to do all this, to make other new things work. Man I love VA. Just keeps getting better! :)