A return must be encountered prior to this "}" Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
ballistics1142
Posts: 12
Joined: 18 Mar 2017, 07:50

A return must be encountered prior to this "}"

12 Nov 2017, 11:50

Hi,

I keep getting this error "A return must be encountered prior to this "}".

I tried putting a return in at the end of the block, but still encounter the error.

Is it a subroutine mess up? or a label not being called?

Code: Select all

#SingleInstance, force
#NoEnv
#Persistent

ChrArray := ["1","1","1","2","2","2","4","3","3","5","6","6","6","7","8","9"]


Loop {
   
    Loop {

startTime := A_TickCount, A_lf := "`n"
Random, interval, 10000, 20000 ; between 10 and 20 seconds just for testing
SetTimer, MySub, 1000
return

MySub:
   ToolTip, % interval A_lf A_TickCount-starttime, 1000, 100
   If ( A_TickCount > starttime+interval)
   return

    
        Send, % RandomChrArray(ChrArray)
        Sleep, % RandomNum(100, 150)
        Send, % RandomChrArray(ChrArray)
        Sleep, % RandomNum(100, 150)
        Send, {tab down}{tab up}
        IfGreater, A_TickCount, % startTime+interval, Break
        
		}
	
		Send, ^0
		Sleep, 1000
		Send, {tab down}{tab up}
		Send, ^0
		Sleep, 1000
		Send, {tab down}{tab up}
		Send, {E down}{E up}
		Sleep, 1000
		Send, {tab down}{tab up}
		Send, {E down}{E up}
		Sleep, 1000
		Send, {tab down}{tab up}
		Send, {E down}{E up}
	
     }

RandomChrArray(ArrayVar) {
    Random, RandChr, 1, % ArrayVar.MaxIndex()
    return ArrayVar[RandChr]
}

/*
RandomChr(Min := 65, Max := 90) { ; A=65, Z=90
    Random, RandChr, % Min, % Max
    return Chr(RandChr)
}
*/

RandomNum(Min, Max) {
    Random, RandNum, % Min, % Max
    return RandNum
}

~space::pause
Noesis
Posts: 299
Joined: 26 Apr 2014, 07:57

Re: A return must be encountered prior to this "}"

13 Nov 2017, 00:38

The issue here is the code doesn't make any logical sense.

The code actually doesn't need both the loops and the timer. You have two infinite loops, I'm not sure why, and you are setting a timer within the inner loop but part of that timer routine is also in the loop that sets it while part of it is presumably only meant to run when called as a timer. Essentially there are some pretty big problems with the code, startTime is always going to be within a few ms of A_Tickcount as it's infinitely updated to be equal to A_Tickcount.

I can't help you fix this code as I have no idea what you're trying to achieve, but I suggest you look at what the code is actually doing and not what you think it's meant to be doing. Ignore the specifics of the error, you don't have a simple syntax error you have a code logic error and you're probably lucky it's and not running in it's current state.
ballistics1142
Posts: 12
Joined: 18 Mar 2017, 07:50

Re: A return must be encountered prior to this "}" [SOLVED]  Topic is solved

13 Nov 2017, 11:24

Noesis wrote:The issue here is the code doesn't make any logical sense.

The code actually doesn't need both the loops and the timer. You have two infinite loops, I'm not sure why, and you are setting a timer within the inner loop but part of that timer routine is also in the loop that sets it while part of it is presumably only meant to run when called as a timer. Essentially there are some pretty big problems with the code, startTime is always going to be within a few ms of A_Tickcount as it's infinitely updated to be equal to A_Tickcount.

I can't help you fix this code as I have no idea what you're trying to achieve, but I suggest you look at what the code is actually doing and not what you think it's meant to be doing. Ignore the specifics of the error, you don't have a simple syntax error you have a code logic error and you're probably lucky it's and not running in it's current state.

Hi,

I have received huge help over at the AHK reddit forum. Big thanks to especially @errorseven
https://www.reddit.com/r/AutoHotkey/com ... r_to_this/

Here are the results;

Code: Select all

#SingleInstance, force
#NoEnv
#Persistent

ChrArray := ["1","1","1","2","2","2","4","3"
            ,"3","5","6","6","6","7","8","9"] ; 
startTime := A_TickCount
SetTimer, MySub, 1000

MySub:
    interval := RandomNum(10000, 20000) ; between 10 and 20 seconds just for testing
    ToolTip, % interval "`n" A_TickCount-starttime, 1000, 100
    loop, 2 {
        Send, % ChrArray[RandomNum(1, ChrArray.MaxIndex())]
        Sleep, % RandomNum(100, 150)
    }
    Send, {tab down}{tab up}
    If (A_TickCount > (startTime+interval)) 
        GoSub MySub2    
return

MySub2:
    SetTimer, MySub, off
        Send, ^0
        Sleep, 1000
        Send, {tab down}{tab up}^0
        Sleep, 1000
        loop, 3 {
            Send, {tab down}{tab up}{E down}{E up}
            Sleep, 1000
        }
        startTime := A_TickCount ; reset to continue looping?
     SetTimer, MySub, on
return

RandomNum(Min, Max) {
    Random, RandNum, % Min, % Max
    return RandNum
}

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Xtra and 31 guests