Hi Larsen,
You are very close...
Any
sub routines will stop at the "return" command. Furthermore it will also return (duh!) the value following it:
001 on Sub_Routine(Param1, Param2)
002 if Logical_Expression is true then
003 return true
004 else
005 return false
006 end if
007 end Sub_Routine
Repeat loops works kinda the same way as they will stop at the "exit" command (no value can be returned though). Now to make use of this you could simple assign the result of your
sub routine to a variable and act upon it:
001 repeat
002 set SubValue to my Sub_Routine(x, y)
003 if SubValue is true then
004 exit repeat
005 end if
006 end repeat
This code can even be simplified by using Applescript default
If... Then... Else... behaviour where the expression is expected to be true to trigger the
Then statement:
001 repeat
002 if my Sub_Routine(x, y) then
003 exit repeat
004 end if
005 end repeat
As you can see, you can
ONLY exit the
Repeat loop from the loop itself. Sub routines are liitle "worlds" by themselves and does not intereact with the calling script. That said, you could also have the sub routine set the value of a property (or global variable) that in tutn can be used to stop your loop:
001 property ExitRepeat : false
002 repeat while ExitRepeat is false
003 my Sub_Routine(x, y)
004 end repeat
005 on Sub_Routine(Param1, Param2)
006 if Logical_Expression is true then
007 set ExitRepeat to true
008 end if
009 end Sub_Routine
BTW, in your code you had "
return false as text"
which is fine, but you have to realize that AppleScript does not consider "false" and false to be equals. So if you want to convert your Boolean values to Strings you will later have to compare these values to Strings as well.