abrogard 0 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? Share this post Link to post Share on other sites
Subz 688 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 Share this post Link to post Share on other sites
argumentum 565 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 1 FrancescoDiMuro reacted to this Follow the link to see my signature's stuff. Share this post Link to post Share on other sites
spudw2k 231 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: AOT Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Share this post Link to post Share on other sites