abrogard Posted June 14, 2019 Share Posted June 14, 2019 I am just beginning. I read that variables are declared with either 'local' or 'global' scope. Then I read that scope depends upon location when declared: if declared in a function they are 'local' if they are declared outside all functions they are 'global'. Does that mean we can simply declare them without any scope specified? Link to comment Share on other sites More sharing options...
Subz Posted June 14, 2019 Share Posted June 14, 2019 Correct, although its best practice to declare scope and also prefix the variable with type of variable, although again not required https://www.autoitscript.com/wiki/Best_coding_practices Link to comment Share on other sites More sharing options...
argumentum Posted June 15, 2019 Share Posted June 15, 2019 58 minutes ago, abrogard said: I am just beginning. @Subz link is important. Why?. Well, structuring your code will save you trouble in the future when you get more creative as you know more and your code ends up too big for a single file. You will end up writing UDFs to simplify the maintenance of the code as you add more stuff to it. So, yes, do declare what you know will be global and what you know will be local. Do it for your mental health FrancescoDiMuro 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
spudw2k Posted June 17, 2019 Share Posted June 17, 2019 As you probably understand about scopes at this point, you should also be aware now of how the scopes could be used to change how variables are accessible from other functions. You can reassign/change the value a global (non-constant) variable within a function, not access other functions local scope variables, or define global variable within a function (though it is not best-practice). Variables declared outside of a function are inherently global, so I can understand why you might not care to distinguish which scope is defined. If you really don't want to declare variable scopes outside functions, that is up to you, but it's not a bad habit to get in to. Having different rules for how you declare function variables versus variables outside of functions is unnecessary and may lead to confusion, IMHO. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF 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