Script not repeating itself

Ask gaming related questions (AHK v1.1 and older)
sebbulon
Posts: 47
Joined: 16 Sep 2020, 12:02

Script not repeating itself

Post by sebbulon » 18 Sep 2020, 12:58

I have a problem with this script after it finishes the pause, after that it does one repetition of "dowork" and then i have to press ''space'' for it to continue, i want it to just continue without me pressing anything.

Code: Select all

#Singleinstance force
#persistent 


Loop
    {

Random, WorkTime, 20, 23  ; seconds
minpause:=14     ; seconds
maxpause:=15      ; seconds



	;;RANDOM VARIABLES;;,

		;;ITEM AND HIGH ALCH;;
			Random x1, 730, 735
			Random y1, 285, 289
		
		;;RANDOM SLEEPS;;
			Random a150, 133, 238
			Random a2432, 2398, 2879



    SetTimer, startpause, % -Worktime*1000
    working:=True
    While working
         gosub dowork     
    random, rand, minpause, maxpause	
    sleep % rand*1000
    random, rand, WorkTime	
    sleep % rand*1000


startpause:


dowork:
Mousemove, x1, y1, 13
	sleep a150
	click
	sleep a150
	click
	sleep a2432
	

return

}

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Script not repeating itself

Post by mikeyww » 18 Sep 2020, 13:13

After your Gosub, the script continues straight through to the bottom because you have no intervening Return. Putting a subroutine inside a loop is also tricky-- not usually helpful, and sometimes leading to unintended effects.

sebbulon
Posts: 47
Joined: 16 Sep 2020, 12:02

Re: Script not repeating itself

Post by sebbulon » 18 Sep 2020, 13:29

mikeyww wrote:
18 Sep 2020, 13:13
After your Gosub, the script continues straight through to the bottom because you have no intervening Return. Putting a subroutine inside a loop is also tricky-- not usually helpful, and sometimes leading to unintended effects.
Ok so any tips on what i can do to fix this?

User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Script not repeating itself

Post by Xtra » 18 Sep 2020, 13:45

Code: Select all

return

}
should be:

Code: Select all

}

return

sebbulon
Posts: 47
Joined: 16 Sep 2020, 12:02

Re: Script not repeating itself

Post by sebbulon » 18 Sep 2020, 13:55

Xtra wrote:
18 Sep 2020, 13:45

Code: Select all

return

}
should be:

Code: Select all

}

return
It says return has to be before {
Attachments
SkärmklippYES.PNG
SkärmklippYES.PNG (12.7 KiB) Viewed 383 times

User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Script not repeating itself

Post by Xtra » 18 Sep 2020, 14:42

That is not the same script in your original post.

See below:

Code: Select all

#Singleinstance force
#persistent 


Loop
{
    Random, WorkTime, 20, 23  ; seconds
    minpause:=14     ; seconds
    maxpause:=15      ; seconds

        ;;RANDOM VARIABLES;;,

        ;;ITEM AND HIGH ALCH;;
            Random x1, 730, 735
            Random y1, 285, 289
        
        ;;RANDOM SLEEPS;;
            Random a150, 133, 238
            Random a2432, 2398, 2879

        SetTimer, startpause, % -Worktime*1000
        working:=True
        While working
             gosub dowork     
        random, rand, minpause, maxpause	
        sleep % rand*1000
        random, rand, WorkTime	
        sleep % rand*1000


    startpause:

    dowork:
    Mousemove, x1, y1, 13
        sleep a150
        click
        sleep a150
        click
        sleep a2432
}         ; <--------
return    ; <--------

sebbulon
Posts: 47
Joined: 16 Sep 2020, 12:02

Re: Script not repeating itself

Post by sebbulon » 18 Sep 2020, 14:56

Xtra wrote:
18 Sep 2020, 14:42
That is not the same script in your original post.

See below:

Code: Select all

#Singleinstance force
#persistent 


Loop
{
    Random, WorkTime, 20, 23  ; seconds
    minpause:=14     ; seconds
    maxpause:=15      ; seconds

        ;;RANDOM VARIABLES;;,

        ;;ITEM AND HIGH ALCH;;
            Random x1, 730, 735
            Random y1, 285, 289
        
        ;;RANDOM SLEEPS;;
            Random a150, 133, 238
            Random a2432, 2398, 2879

        SetTimer, startpause, % -Worktime*1000
        working:=True
        While working
             gosub dowork     
        random, rand, minpause, maxpause	
        sleep % rand*1000
        random, rand, WorkTime	
        sleep % rand*1000


    startpause:

    dowork:
    Mousemove, x1, y1, 13
        sleep a150
        click
        sleep a150
        click
        sleep a2432
}         ; <--------
return    ; <--------
The one i posted was then i tried to put return after } as you said in the same script and i got that error message. It is the same script except that return is after }, instead of before

sebbulon
Posts: 47
Joined: 16 Sep 2020, 12:02

Re: Script not repeating itself

Post by sebbulon » 18 Sep 2020, 14:59

Xtra wrote:
18 Sep 2020, 14:42
That is not the same script in your original post.

See below:

Code: Select all

#Singleinstance force
#persistent 


Loop
{
    Random, WorkTime, 20, 23  ; seconds
    minpause:=14     ; seconds
    maxpause:=15      ; seconds

        ;;RANDOM VARIABLES;;,

        ;;ITEM AND HIGH ALCH;;
            Random x1, 730, 735
            Random y1, 285, 289
        
        ;;RANDOM SLEEPS;;
            Random a150, 133, 238
            Random a2432, 2398, 2879

        SetTimer, startpause, % -Worktime*1000
        working:=True
        While working
             gosub dowork     
        random, rand, minpause, maxpause	
        sleep % rand*1000
        random, rand, WorkTime	
        sleep % rand*1000


    startpause:

    dowork:
    Mousemove, x1, y1, 13
        sleep a150
        click
        sleep a150
        click
        sleep a2432
}         ; <--------
return    ; <--------
The only difference is the last thing which only occurs when im done, and is not suppose to happend more than once so thats not the problem i think? But i still cant put return after as you wanted

Post Reply

Return to “Gaming Help (v1)”