Macro stops working after GoSub is executed

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Hunkel
Newbie
Posts: 5
Joined: Wed Oct 07, 2015 2:24 pm

Macro stops working after GoSub is executed

Post by Hunkel » Wed Oct 07, 2015 3:10 pm

I am using windows 7 . Every time i run my macro it works well until it reaches part where it goes GoSub, after GoSub part of code is executed the macro stops working as if someone clicked stop, and the rest of my code doesn't get executed. Is that some kind of bug ? I was running code with GoSub in it on windows xp like 2 years ago and it worked, am wondering why its not working now. is there any alternative to GoSub i don't know it works on windows 7.

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Macro stops working after GoSub is executed

Post by hagchr » Wed Oct 07, 2015 3:13 pm

Hi, Should work. Can you post an example where it does not work.

Hunkel
Newbie
Posts: 5
Joined: Wed Oct 07, 2015 2:24 pm

Re: Macro stops working after GoSub is executed

Post by Hunkel » Wed Oct 07, 2015 3:22 pm

I am using Macro Scheduler 11 maybe i need to upgrade it.


These are mine GoSubs executors

Code: Select all

Let>a=0
Repeat>a
    Let>a=a+1

// 1 
    MouseMove>280,1900
wait 5
LClick
wait 1
    MouseMove>130,1800
wait 2

LClick
wait 2
GoSub>fight
wait 1

// 2 
    MouseMove>280,1900
wait 5
LClick
wait 1
    MouseMove>340,1800
wait 2

LClick
wait 2
GoSub>fight
wait 1

// 3 
    MouseMove>280,1900
wait 5
LClick
wait 1
    MouseMove>560,1800
wait 2

LClick
wait 2
GoSub>fight
wait 1

// 4 
    MouseMove>280,1900
wait 5
LClick
wait 1
    MouseMove>770,1800
wait 2

LClick
wait 2
GoSub>fight
wait 1

// 5
    MouseMove>280,1900
wait 5
LClick
wait 1
    MouseMove>1000,1800
wait 2

LClick
wait 2
GoSub>fight

wait 600



Until>a>5
Last edited by Hunkel on Wed Oct 07, 2015 4:37 pm, edited 1 time in total.

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Macro stops working after GoSub is executed

Post by hagchr » Wed Oct 07, 2015 3:30 pm

Hi, One thing I note in the SRT is that you have wait 10, instead of wait>10. That will cause it to hang.

Hunkel
Newbie
Posts: 5
Joined: Wed Oct 07, 2015 2:24 pm

Re: Macro stops working after GoSub is executed

Post by Hunkel » Wed Oct 07, 2015 3:40 pm

Mine first GoSub code gets executed and is working properly. Problem starts after my first GoSub code ends, my macro then stops and is not executing any more code.

I changed wait 10 to wait>10 to see if i will get any difference but it doesn't make no difference i still have the same problem.

Hunkel
Newbie
Posts: 5
Joined: Wed Oct 07, 2015 2:24 pm

Re: Macro stops working after GoSub is executed

Post by Hunkel » Wed Oct 07, 2015 4:25 pm

Ok i just added number 1 to my GoSub name and changed it from srt>fight to srt>fight1 and is working now. Could be bug due to short name or lacking a number in it.

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Macro stops working after GoSub is executed

Post by hagchr » Wed Oct 07, 2015 4:36 pm

Hi, great that it now works (although not fully sure what caused the problem). Sorry, I was mistaken, wait 10 seems to work fine.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Macro stops working after GoSub is executed

Post by JRL » Wed Oct 07, 2015 6:29 pm

Without seeing the rest of your code my guess would be you have a variable named "fight" somewhere in the script. When "fight" has a value and you do a GoSub>fight, you are trying to go to a subroutine with a name that is the value of the variable.

Code: Select all

GoSub>fight
Let>fight=1
GoSub>fight

SRT>fight
  MDL>fight found
END>fight

Hunkel
Newbie
Posts: 5
Joined: Wed Oct 07, 2015 2:24 pm

Re: Macro stops working after GoSub is executed

Post by Hunkel » Wed Oct 07, 2015 8:14 pm

I do have a image finder named fight it might be that

Code: Select all

GetScreenRes>sX,sY
ScreenCapture>0,0,sX,sY,C:\Programs\Macro Scheduler 11\scre\screen.bmp
FindImagePos>C:\Programs\Macro Scheduler 11\pictures\fight.bmp,C:\Programs\Macro Scheduler 11\scre\screen.bmp,60,1,XPos,YPos,fight

     MouseMove>XPos_0,YPos_0

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Macro stops working after GoSub is executed

Post by JRL » Wed Oct 07, 2015 8:23 pm

You got it!

As soon as you run that FindImagePos> line the term "fight" is assigned a value (the number of images found). Once "fight" has a value, it is no longer useful as a subroutine name.

User avatar
AntoniusMomac
Junior Coder
Posts: 20
Joined: Fri Dec 07, 2007 7:46 am
Location: New York City, NY

Re: Macro stops working after GoSub is executed

Post by AntoniusMomac » Thu Oct 29, 2015 8:08 pm

JRL,

I've been doing this for awhile now and totally made that mistake. In fact, until reading your answer I totally overlooked the possibility of making such a silly mistake :oops: . Variable naming 101, sign me up. :D

Thank you so much for your help. It was brilliant. :)
Love Simple!! "Simplicity means the achievement of maximum effect with minimum means" - Dr. Koichi Kawana, Architect, designed the botanical gardens

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Macro stops working after GoSub is executed

Post by armsys » Thu Oct 29, 2015 10:13 pm

Another time-saving troubleshooting technique is to insert **BREAKPOINT** (case insensitive) at the line of interest.

Code: Select all

GetScreenRes>sX,sY
**BREAKPOINT**
ScreenCapture>0,0,sX,sY,C:\Programs\Macro Scheduler 11\scre\screen.bmp
FindImagePos>C:\Programs\Macro Scheduler 11\pictures\fight.bmp,C:\Programs\Macro Scheduler 11\scre\screen.bmp,60,1,XPos,YPos,fight
MouseMove>XPos_0,YPos_0

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Macro stops working after GoSub is executed

Post by Grovkillen » Fri Oct 30, 2015 9:10 am

Please feel free to use my script to find duplicates (post no. 6).

viewtopic.php?f=2&t=7733
Let>ME=%Script%

Running: 15.0.27
version history

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Macro stops working after GoSub is executed

Post by armsys » Fri Oct 30, 2015 9:24 am

Hi Grovkillen,
Grovkillen wrote:Please feel free to use my script to find duplicates (post no. 6).
viewtopic.php?f=2&t=7733
Thank you for referring to the extremely valuable thread. It's my first time to become aware that MS can call dynamically-naming subroutines.

Code: Select all

Let>I=2
Let>TEST={if(%I%=1,"Heaven","Hell")}
Gosub>%TEST%
SRT>Heaven
  MDL>Heaven
END>Heaven
SRT>Hell
  MDL>Hell
END>Hell

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Macro stops working after GoSub is executed

Post by armsys » Fri Oct 30, 2015 9:48 am

Hi Grovkillen,
Grovkillen wrote:Please feel free to use my script to find duplicates (post no. 6).
viewtopic.php?f=2&t=7733
Your script is absolutely useful in creating a list of variables and their occurrences. Hope Macro Scheduler will include your debugging tool in the future.
Thank you for sharing your debugging script with us. :lol:

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