Guest tamirousmc77 Posted March 15, 2005 Share Posted March 15, 2005 I have had issues where a function run inside another function fails or does not run. Is this by design or is there something missing? Any thoughts or suggestions are welcome. Need this information for a high priority script I am finishing up. Link to comment Share on other sites More sharing options...
SlimShady Posted March 15, 2005 Share Posted March 15, 2005 You can't nest functions in functions in AutoIt. I haven't programmed much but this does make sense to me. Link to comment Share on other sites More sharing options...
Blue_Drache Posted March 15, 2005 Share Posted March 15, 2005 (edited) You can't nest functions in functions in AutoIt.I haven't programmed much but this does make sense to me.<{POST_SNAPBACK}>Why not? My string manipulation examples are a perfect demonstration of nested functions. See below:I have had issues where a function run inside another function fails or does not run. Is this by design or is there something missing? Any thoughts or suggestions are welcome. Need this information for a high priority script I am finishing up. <{POST_SNAPBACK}>Functions can call other functions all day long. It's called "recursion" and you are allowed *checks help file* "Maximum depth of recursive function calls: 384 levels"That's very deep, and if you run out of recursive space, then you need to restructure your script.Example:$ppn = StringUpper(StringRight(StringMid($screen, $tem, 23), 6))There's 3 levels of recursion on default functions in that example. StringMid is performed first, then StringRight, and finally StringUpper.Example 2:If Inelg($a,"400","273") = 1 then MsgBox(0x23,"Stop!","Found an error code!") Func Inelg($sScreen, $sCode1, $sCode2 = "") GetScreen($sScreen) Local $inel $inel = ClipGet() If @error Then Return 0 $inel = StringStripWS($inel, 8) $inel = StringMid($inel, StringInStr($inel, "INELRSNS:"), 30) $inel = StringTrimLeft($inel, 9) $inel = StringLeft($inel, 9) If StringRight($inel, 3) = $sCode1 Or StringLeft($inel, 3) = $sCode1 Or StringTrimLeft(StringLeft($inel, 6), 3) = $sCode1 _ Or StringRight($inel, 3) = $sCode2 Or StringLeft($inel, 3) = $sCode2 Or StringTrimLeft(StringLeft($inel, 6), 3) = $sCode2 _ Then Return 1 Return 0 EndFunc ;==>Inelg Func GetScreen($screen) WinActivate($screen) Send("{ctrldown}{insert 2}{ctrlup}") EndFunc ;==>GetScreenThe above uses the GetScreen function within the Inelg function. Edited March 15, 2005 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
Valik Posted March 15, 2005 Share Posted March 15, 2005 Blue_Drache, you demonstrate nesting but explain it as if it were recursion. There is a difference. Recursion is when you call functionA from within functionA or from within functionB which calls functionA. Or in other words. A function is called multiple times before returning. Although I'm sure the recursion limit is applied to nested function calls as well, it's still not actually recursion so shouldn't be described using that terminology. Example of recursion: Func functionA() functionA() EndFunc As to the original question, it's too vague. It could mean defining local functions: Func A() Func B() ; Do Stuff EndFunc B() EndFunc ; B() <--- Would be illegal, B would be local to A() That is of course, not supported. It could mean nested function calls (As demonstrated by Blue_Drache): $ppn = StringUpper(StringRight(StringMid($screen, $tem, 23), 6)) It could mean calling functions from within another function: Func A() StringUpper("test") EndFunc Or it could mean something else entirely. Not enough information has been provided. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now