Jump to content

Help With Loops...


Recommended Posts

Okay, I'm not quite sure how to describe what I need help with, but let's give it a shot...

Basically, I've written a script that will monitor certain parts of a window and search for certain keywords and upon finding any of the keywords a sound is played. My problem is that I need it to run pretty quick. I'm using a delay between actions of 100ms. Any slower than that is unacceptable. Now, since it's running fast I fear that it's glitching from time to time and giving false alarms so what I'd like to do is make a new function within my script and have it run the check for keywords only once every 4 loops instead of every time. As of now it's kinda like this...

func check1()

func check2()

func check4()

func check3()

func check4()

all running with 100ms delay between each. Let's say I want to make it run like this...

func check1()

func check2()

func check3()

func check4()

func check1()

func check2()

func check3()

func check4()

func check1()

func check2()

func check3()

func check4()

func check1()

func check2()

func check4()

func check3()

func check4()

Notice how it runs 1 2 3 4, 1 2 3 4, 1 2 3 4 then it switches to 1 2 4 3 4...I only want it to run 2 then 4 every 4 loops...If anybody can help me figure this out I would really appreciate it.

I hope this makes sense to you people because I'm pretty new to scripting and am not quite sure how to explain it properly. :)

Also, I was wondering if somebody could aim me in the direction of help on having a script search for certain colors on the screen, but only in a certain part of the screen.

Thank you in advance to anybody that replies. All help is appreciated. :mellow:

As a side note, the reason I want to add the above described feature is also to avoid getting a recurrsion limit error. I've noticed that when a couple functions loop for too long you get the error and the script comes to a halt. While my script is running it sometimes needs to run func check1() ---> func check2() -----> func check1() etc...over and over and after awhile the error occurs. From what I've seen it only happens when 1 or 2 functions loop over and over, but not when it's 3 or more. Maybe somebody can shine some light on why this happens?

Edited by Nefarious
Link to comment
Share on other sites

so u want it to run func 1 fours times, then run func 2 four times then run func 3 four times?\

u could do something like

for $i = 1 to 4

func check()

next

do another check

I need it to run through functions 1 - 4 four times before it runs function 4 after function 2 once. I'm guessing I would need to set up a new function that would monitor how many times the script has run it's cycle then on the 4th. time it would toss in func check4() after func check2().

Link to comment
Share on other sites

  • Moderators

CheckFunc1()

Func CheckFunc1()
    Local $Loop = 1
    While $Loop <= 4; Will loop 4 times
        MsgBox(0, 'func 1', 'test')
    ;Do function stuff
        CheckFunc2()
        $Loop = $Loop + 1
    WEnd
EndFunc

Func CheckFunc2()
    MsgBox(0, 'func 2', 'test')
;Do Function stuff
    CheckFunc3()
EndFunc

Func CheckFunc3()
    MsgBox(0, 'func 3', 'test')
;Do Function stuff
    CheckFunc4()
EndFunc

Func CheckFunc4()
    MsgBox(0, 'func 4', 'test')
;Do Function stuff
;Now it will return to checkfunc3() / then to checkfunc2() / then to checkfunc1()
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

CheckFunc1()

Func CheckFunc1()
    Local $Loop = 1
    While $Loop <= 4; Will loop 4 times
        MsgBox(0, 'func 1', 'test')
;Do function stuff
        CheckFunc2()
        $Loop = $Loop + 1
    WEnd
EndFunc

Func CheckFunc2()
    MsgBox(0, 'func 2', 'test')
;Do Function stuff
    CheckFunc3()
EndFunc

Func CheckFunc3()
    MsgBox(0, 'func 3', 'test')
;Do Function stuff
    CheckFunc4()
EndFunc

Func CheckFunc4()
    MsgBox(0, 'func 4', 'test')
;Do Function stuff
;Now it will return to checkfunc3() / then to checkfunc2() / then to checkfunc1()
EndFunc

As much as I appreciate the help, I'm not fully understanding how to implement this into my current code. Perhaps I can get somebody to add me to their MSN and I'll show them what I have and get further advice on how to fix it up.

Fugyoubish@hotmail.com

Link to comment
Share on other sites

As much as I appreciate the help, I'm not fully understanding how to implement this into my current code. Perhaps I can get somebody to add me to their MSN and I'll show them what I have and get further advice on how to fix it up.

Fugyoubish@hotmail.com

umm if u look u will see do function stuff, just add all the stuff that does the check right there, and u can probaly delete the msgbox cuz it was just a test if it actualy worked

Link to comment
Share on other sites

umm if u look u will see do function stuff, just add all the stuff that does the check right there, and u can probaly delete the msgbox cuz it was just a test if it actualy worked

Well, according to the above code, once it finishes it's going to reverse itself and run the functions in the reverse order...if I do that then once it gets back to the 2nd. function it's going to get stuck and I'll end up erroring out. check2 can't run until check1 is completed. Hard to describe unless you see my code, but I'm not comfortable with posting all my code here.

Link to comment
Share on other sites

well im just gonna stick with if u want anymore help u might as well post ur code cuz the way u say it its just so confusing....

I have no problem showing my code to an individual, but posting it in public is what I'm trying to avoid. Again, if somebody will add me to MSN or even send me an email, I'll gladly give you what I have to look at.

MSN or email @ fugyoubish@hotmail.com

Link to comment
Share on other sites

  • Moderators

You could just find someone that you feel will help and PM them with it, no need for outside intervention :).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Wanted to thank anybody who responded. Just coming here got my wheels turning and I figured out a way to make this work for me. It's probably not the cleanest of code, but it works. My main problem was having the script give false alarms from what I figure was caused by running so fast. It was checking a couple parts of the screen for keywords and I have a feeling that somewhere along the way stuff that was copied to the clipboard was getting stuck and the next function would read it and give off a false alarm. I solved the problem by adding one simple line of code to the 2nd. function that copied code to the clipboard...first thing the function does is a simple...

ClipPut("Erased")

This seems to have solved my problem by ensuring the clipboard is clean before the next function writes to the clipboard and thus eliminating the need to slow down the script a bit by making the 2nd. function run only once every 4 loops of the script. Thank you for the input though, I'm sure the code given will come in handy somewhere for me. :)

Edited by Nefarious
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...