geekycoder Posted January 13, 2010 Share Posted January 13, 2010 Is there a main function or equivalent for AutoIt just like Python and Java to make script testing convenient ? def main(): # the main code goes here if __name__ == "__main__": main() I will like the script to run the main func when the script is executed, and ignore the main when run as library. Currently the "main" function has to be commented and uncommented to be tested. thx Link to comment Share on other sites More sharing options...
JRowe Posted January 13, 2010 Share Posted January 13, 2010 (edited) Not formally, no. The script itself is the scope of execution, e.g. AutoIt will execute the script from top to bottom. You encapsulate functions using Func / EndFunc, and you can create a "main" loop by using the control keywords like While/Wend or For/Next. Generally speaking, most people put their code between While/Wend, like this: $someVariable = "blah blah" Global $SomeGlobalVariable = "blah" $main = 10 $i = 0 While $main > 0 $i = $i + 1 MsgBox(0, "This is your main loop", "We will execute " & 10-$i & " more times before exiting the main loop") $main -= 1 Wend Func SomeFunc($parameterYay) ;commented line ;this function never gets called, but it's here to demonstrate scope MsgBox(0, "This is Somefunc Speaking", "This is outside the main loop") EndFunc That's a pretty basic outline for how a lot of scripts are written. Some people are more formal, others are much less, and the different flow control keywords have different advantages depending on what you're doing. Check out the help file and the stickies on this forum, it will help you get a good grasp on the language much faster. Edited January 13, 2010 by JRowe [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
jvanegmond Posted January 13, 2010 Share Posted January 13, 2010 (edited) You can use the @ScriptName macro to see which script is currently being executed.Edit: Clarification. Your library would look like this:If @ScriptName = "ThisLibName.au3" Then _LibTestMain() Func _LibFunc1() EndFunc Func _LibFunc2() EndFunc Func _LibTestMain() ; Test this library _LibFunc1() _LibFunc2() EndFuncMain script:#include "ThisLibName.au3" ; Dowhatever Edited January 13, 2010 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
geekycoder Posted January 13, 2010 Author Share Posted January 13, 2010 Thank for the suggestions. 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