evilertoaster Posted June 24, 2008 Share Posted June 24, 2008 Hum I'm finding so many quirks latley in autoit... Ok how bout this- For $n=1 to 2 _Foo() Next Func _Foo() $n=0 EndFunc Infinite loop... But the $n in the for loop should be local... so why does the _Foo() function change it? Link to comment Share on other sites More sharing options...
weaponx Posted June 24, 2008 Share Posted June 24, 2008 $n is being declared as global by the For statement. Use Local inside the function to stop the infinite loop. Link to comment Share on other sites More sharing options...
Anonymouse Posted June 24, 2008 Share Posted June 24, 2008 (edited) $n is being declared as global by the For statement. Use Local inside the function to stop the infinite loop. I had a similar issues with this, best bet is to use a different variable other than n, maybe $i Global $i[8] Func _Main() $i = blah EndFunc While 1 Dim $i GUICtrlRead($i, blah...) WEnd This will cancel out $i since it is being claimed Dim, after global. It overrides the $i in the function even though it's global because of the Dim.. Sorry about my ill way of explaining it if you don't understand. Edited June 24, 2008 by Anonymouse children may smile; the wise ponder- Dr. Holmes of Hardvard Medical School on an Ether BingeLove Makes The World Go Round?So does five shots of tequila. What's your point?[quote name='Valik' date='Jun 5 2008, 05:13 PM']wraithdu, 24 hours. Said I have a bad attitude, just driving the point home with a ban.[/quote]This is classic. :) Link to comment Share on other sites More sharing options...
evilertoaster Posted June 24, 2008 Author Share Posted June 24, 2008 $n is being declared as global by the For statement. Use Local inside the function to stop the infinite loop. But from the helpfile- Loop based on an expression. For <variable> = <start> To <stop> [step <stepval>] statements ... Next Parameters variable The variable used for the count. start The initial numeric value of the variable. stop The final numeric value of the variable. stepval [optional] The numeric value (possibly fractional) that the count is increased by each loop. Default is 1. Remarks The Variable will be created automatically with a LOCAL scope, even when MustDeclareVars is on. Link to comment Share on other sites More sharing options...
evilertoaster Posted June 24, 2008 Author Share Posted June 24, 2008 I had a similar issues with this, best bet is to use a different variable other than n, maybe $i Global $i[8] Func _Main() $i = blah EndFunc While 1 Dim $i GUICtrlRead($i, blah...) WEnd This will cancel out $i since it is being claimed Dim, after global. It overrides the $i in the function even though it's global because of the Dim.. Sorry about my ill way of explaining it if you don't understand.I know perfectly well what its doing and how to aviod it...I'm woundering more-so why it's doing that, in particular if it's intened or always been that way... Link to comment Share on other sites More sharing options...
weaponx Posted June 24, 2008 Share Posted June 24, 2008 (edited) For $x=1 to 1 $Result = IsDeclared("x") If $Result = 1 Then ConsoleWrite("Variable is global" & @CRLF) ElseIf $Result = -1 Then ConsoleWrite("Variable is local" & @CRLF) EndIf Next _Foo() Func _Foo() For $n=1 to 1 $Result = IsDeclared("n") If $Result = 1 Then ConsoleWrite("Variable is global" & @CRLF) ElseIf $Result = -1 Then ConsoleWrite("Variable is local" & @CRLF) EndIf Next EndFunc Variable is global Variable is local Documentation is wrong. The documentation for IsDeclared() says: Returns 1 for Global variable or variable declared outside functions. Edited June 24, 2008 by weaponx Link to comment Share on other sites More sharing options...
evilertoaster Posted June 24, 2008 Author Share Posted June 24, 2008 (edited) So that tells me it doesn't create a local variable for For-Next loops if the For-Next is not in a function, or (without double negatives), For-Next will only create a local variable if the For-Next is inside a function. Maybe a slight wording change to the help file is in order? Edited June 24, 2008 by evilertoaster 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