Conditional do loops (goto vs gosub?)

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
trapedui
Newbie
Posts: 4
Joined: Tue Dec 07, 2010 2:44 pm

Conditional do loops (goto vs gosub?)

Post by trapedui » Wed Dec 08, 2010 4:51 pm

This question builds on a resolved thread I created yesterday.
http://www.mjtnet.com/usergroup/viewtopic.php?t=6601

I have created a new thread, because this is a fundamentally different problem than the one Marcus helped me work through yesterday.

I can't seem to get my code to post correctly on this forum, so I posted it to FreeTextHost.
http://freetexthost.com/q43bi1alc2

What I am trying to do is check a single pixel on the screen. As long as it is dark, I run the primary routine, FastClick. However, if it is not dark, I want to run SlowClick, then check again after 5, 10 and 30 seconds. If it is still not dark, the script should end.

I have debugged the code and it seems that most of it works. The problem I am having is I don't know how to return to the top of the conditional tests after running FastClick or SlowClick. After FastClick runs, it goes up to the next if statement in CycleDarkCheck, rather than starting at the beginning. After doing some research, I think this may have to do with the difference between goto and gosub, but I am really not sure. After 48 hours, I am starting to really enjoy the challenges of simple programming, but I am still a novice.

Your help would be greatly appreciated.
Thanks.

I have edited this post to include the code below. To read, you need to replace {symbol for less than} with the symbol for less than. Somehow, the combination of less thans follwed by a greater thans, truncated the code in between.

Code: Select all

Let>x=0
Label>CycleDarkCheck
Repeat>x

//if pixel is dark, do FastClick, otherwise wait 2 seconds and try again
 GetPixelColor>112,152,color
    If>%color%{symbol for less than}5000000,FastClick
    Wait>2

//if pixel is dark now, do SlowClick, otherwise wait 5, 10, 30 seconds
 GetPixelColor>112,152,color
    If>%color%{symbol for less than}5000000,SlowClick
    Wait>5
 GetPixelColor>112,152,color
    If>%color%{symbol for less than}5000000,SlowClick
    Wait>10
  GetPixelColor>112,152,color
    If>%color%{symbol for less than}5000000,SlowClick
    Wait>30

//if pixel is still not dark, end script
GetPixelColor>112,152,color
    If>%color%{symbol for less than}5000000,SlowClick,EOF

//end script when counter = 200, if not already terminated
Until>x=200

//Click, wait, press "a", wait, advance counter by 1 and return to beginning of CycleDarkCheck
SRT>FastClick
 MouseMove>900,320
 LClick
 GoSub>RandShortWait
 press a
 GoSub>RandShortWait
Let>x=x+1
End>FastClick

//Click, wait, press "a", wait, advance counter by 4 and return to beginning of CycleDarkCheck
SRT>SlowClick
 MouseMove>900,320
 LClick
 GoSub>RandLongWait
 press a
 GoSub>RandLongWait
Let>x=x+4
End>SlowClick

//Wait a random amount of time betwen 0.25 and 0.30 seconds
SRT>RandShortWait
 Random>50,rndRange
 Let>rndTime={(%rndRange%+250)/1000}
 Wait>rndTime
End>RandShortWait

//Wait a random amount of time betwen 1.00 and 1.20 seconds
SRT>RandLongWait
 Random>200,rndRange
 Let>rndTime={(%rndRange%+1000)/1000}
 Wait>rndTime
End>RandLongWait

Label>EOF

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Dec 08, 2010 8:02 pm

I can't for the life of me follow what you are trying to do here.

But maybe this will provide some clues:

Code: Select all

Repeat>x
  //if pixel is dark, do FastClick, otherwise wait 2 seconds and try again
  GetPixelColor>112,152,color
  If>%color%<5000000
    GoSub>FastClick
    Wait>2
  Else
    GoSub>SlowClick
    Wait>5
  Endif
  Let>x=x+1
Until>x=200
I don't get what wait 5,10, 30 seconds means. The above will run FastClick and then wait 2 seconds if the color is less than 5000000 and then loop back otherwise it will run SlowClick and wait 5 seconds and then loop back
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

trapedui
Newbie
Posts: 4
Joined: Tue Dec 07, 2010 2:44 pm

Post by trapedui » Thu Dec 09, 2010 3:16 pm

Thanks for helping me once again Marcus. After your post, I realized that my concept was unnecessarily complicated. I tweaked the short script you provided and now have everything working very well.

In case I want to add more bells and whistles later, I will take hints from another thread I found last night.

http://www.mjtnet.com/usergroup/viewtopic.php?t=6247

This appears to have the correct syntax for multiple conditional statements. However, I am not sure that I even need that.

Thanks again. Case resolved.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts