Sign in to follow this  
Followers 0
tigerray00

Help with Declarations

10 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by monoscout999

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 = 2

ConsoleWrite("$var")

EndFunc

Func Action2()

Local $var

$var = 4

ConsoleWrite("$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 by tigerray00

Share this post


Link to post
Share on other sites

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


Share this post


Link to post
Share on other sites

sweet! thanks a bunch

Share this post


Link to post
Share on other sites

The local varable is destroyed after you exit the function.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Ok, ty for the info everyone :mellow:

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 by tigerray00

Share this post


Link to post
Share on other sites

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.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0