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

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

songoku
Posts: 73
Joined: 12 Apr 2018, 13:22

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

04 Sep 2018, 16:22

Hallo zsm,
beim Script Ablauf bekomme ich ab und zu diese Fehlermeldung:

Code: Select all


Error:  A "return" must be encountered prior to this "}".

	Line#
	052: WinActivate,Mozilla Firefox
	053: Sleep,100
	054: Send,^w
	055: Sleep,333
	056: }
	057: Else
	058: Return
--->	059: }
	063: Reload
	066: Edit
	069: ExitApp
	070: Exit
	071: Exit
	071: Exit

The current thread will exit.

Code: Select all

F7::

Loop {
start:
SetTitleMatchMode, 2
IfWinActive, Mozilla Firefox
{
SetTitleMatchMode, 2
WinActivate, Mozilla Firefox
sleep, 333
clipboard =
MouseMove, 193, 266, 30
Sleep, 1000
Click, 193, 266, 3
Sleep, 1000
Send, ^c
ClipWait,2
nht = red,green,blue
If Clipboard contains %nht% 
{
Send, ^w
sleep, 3000
Gosub, start
}

ImageSearch, FoundX, FoundY, 11, 4, 1283, 37, *33 laut.png
While (ErrorLevel)
{
    CoordMode, Pixel, Screen
ImageSearch, FoundX, FoundY, 11, 4, 1283, 37, *33 laut.png
    If ErrorLevel = 1
    {
        	Click, 437, 559
	sleep, 5000
    }
}


CoordMode, Mouse, Screen
Click, Right, 437, 559
sleep, 500
SendInput {o}
sleep, 1000
SendInput {Enter}
Clipwait
WinActivate, Unbenannt - Editor
SendInput, % Clipboard
sleep, 150
Send {Enter}
sleep, 300
SetTitleMatchMode, 2
WinActivate, Mozilla Firefox
sleep, 100
Send, ^w
sleep, 333
}
Else
return
}


F8::
reload

F9::
Edit

F12::
ExitApp
Ich verstehe das so, dass vorher return gesetzt werden muss. Habe einiges ausprobiert, doch weiss nicht wo ich return setzen soll

Denke und liebe Grüße
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

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

05 Sep 2018, 02:42

script.cpp wrote:

Code: Select all

case ACT_BLOCK_END:
// Don't count block-begin/end against the total since they should be nearly instantaneous:
//++g_script.mLinesExecutedThisCycle;
if (aMode != UNTIL_BLOCK_END)
	// Rajat found a way for this to happen that basically amounts to this:
	// If within a loop you gosub a label that is also inside of the block, and
	// that label sometimes doesn't return (i.e. due to a missing "return" somewhere
	// in its flow of control), the loop(s)'s block-end symbols will be encountered
	// by the subroutine, and these symbols don't have meaning to it.  In other words,
	// the subroutine has put us into a waiting-for-return state rather than a
	// waiting-for-block-end state, so when block-end's are encountered, that is
	// considered a runtime error:
	return line->LineError(_T("A \"return\" must be encountered prior to this \"}\"."));  // Former error msg was "Unexpected end-of-block (Gosub without Return?)."
return OK; // It's the caller's responsibility to resume execution at the next line, if appropriate.
dh, start: label löschen und Gosub, start durch continue ersetzen
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

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

05 Sep 2018, 02:48

Weil ich das schon fertig habe:

Moin,

das wird wahrscheinlich durch die folgenden Anweisungen verursacht:

Code: Select all

Loop {
   start: ; <<<<<
   SetTitleMatchMode, 2
   IfWinActive, Mozilla Firefox
   {
   ...
   ...
      If Clipboard contains %nht%
      {
         Send, ^w
         sleep, 3000
         Gosub, start  ; <<<<<
      }
      ...
      ...
   }
}
Es ist generell keine gute Idee, eine Sprungmarke wie Start: in eine Schleife zu legen. Wenn Du die dann auch noch mit Gosub anstelle von Goto anspringst, scheint AHK ein 'ordentliches' Ende der Subroutine mit Return vor dem Ende des aktuellen Schleifenblocks zu erwarten.

Wenn Du - wie ich glaube - aus einer Schleife heraus einfach nur den nächsten Durchlauf starten willst, hat AHK dafür die Anweisung Continue:

Code: Select all

      If Clipboard contains %nht%
      {
         Send, ^w
         sleep, 3000
         Continue  ; <<<<<
      }
Das Label Start: kannst Du dann entfernen.

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: WPLPHSS and 114 guests