tigerray00 Posted September 3, 2011 Share Posted September 3, 2011 As I'm new to this I'm studying as diligently as I can and going through the help file as much as possible, and doing searches and reading here on the forums. But, for the question I'm about to ask the help file is just too vague on the subject and I can't seem to find any posts on my question specifically.(might actually be more than one) I understand the purpose of declaring your variables. This is kind of obvious once you start using them. The questions are these: What exactly is the difference between Global, and Local? The help file just said it was for the scope, but what scope? What is the global scope, and what is the local scope? And how do I decide which variables must be declared and which don't really have to be? I've seen a lot of scripts on here that use either global or local, and I've seen ones that don't declare every variable used even though there is a declaration of variables made. And one more, I heard mention of a guide of some type and it sounded like a learners guide, something more in depth than the tutorials in the help file. If this is the case where can I find it? I can't seem to find a seperate download for anything like a learners guide. Link to comment Share on other sites More sharing options...
monoscout999 Posted September 3, 2011 Share Posted September 3, 2011 (edited) The basic explaination is.. Global variables can be used in any part of the script, the local only exists in the funcion where it were created..(sorry my bad english) They are useful when you have to realize calculations and need to store temporary data for these calculations. I don´t know any guide, if i found one i will link it in this topic. Edited September 3, 2011 by monoscout999 Link to comment Share on other sites More sharing options...
nAutoIT Posted September 3, 2011 Share Posted September 3, 2011 Example: $g = 0 $l = 0 AddOne() MsgBox(1, "", "Global: " & $g & @CRLF & "Local: " & $l) Func AddOne() Global $g = 0 Local $l = 0 $g += 1 $l += 1 EndFunc Link to comment Share on other sites More sharing options...
tigerray00 Posted September 3, 2011 Author Share Posted September 3, 2011 (edited) ok, so if I use a variable inside a function and declare it local, can I use the same variable (text name of the variable, not the same variable) inside a seperate function if I declare it as Local in each function? for instance Func Action1()Local $var$var = 2ConsoleWrite("$var")EndFunc Func Action2()Local $var$var = 4ConsoleWrite("$var")EndFunc $var would only = 2 when in Action(), and 4 only in Action2() $var being the text and having whatever expression or function for it not being the same would that be ok as long as I don't use $var in a different part of the script without also declaring it there? Edited September 3, 2011 by tigerray00 Link to comment Share on other sites More sharing options...
zac23 Posted September 3, 2011 Share Posted September 3, 2011 Example: $g = 0 $l = 0 AddOne() MsgBox(1, "", "Global: " & $g & @CRLF & "Local: " & $l) Func AddOne() Global $g = 0 Local $l = 0 $g += 1 $l += 1 EndFunc you have declared the global inside the local scope i think. Autoit 123 is a good starting point if your just starting out Link to comment Share on other sites More sharing options...
tigerray00 Posted September 3, 2011 Author Share Posted September 3, 2011 sweet! thanks a bunch Link to comment Share on other sites More sharing options...
monoscout999 Posted September 3, 2011 Share Posted September 3, 2011 The local varable is destroyed after you exit the function. Link to comment Share on other sites More sharing options...
tigerray00 Posted September 3, 2011 Author Share Posted September 3, 2011 (edited) Ok, ty for the info everyone Ok, so now I understand the scopes So you'd only have to declare variables that actually require a declaration statement due to usage. Edited September 3, 2011 by tigerray00 Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted September 3, 2011 Share Posted September 3, 2011 There's a list of tutorials in the wiki. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
guinness Posted September 3, 2011 Share Posted September 3, 2011 Put #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 at the top of your script to see what variables aren't declared correctly. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 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