DaRkf0x Posted November 28, 2010 Share Posted November 28, 2010 Hello everyone Sorry if this seems pretty dumb to all of you, but i just can't understand how to make a function that uses two variables and then call that function giving them different values everytime. Imagine I want the function to click four different places on the screen, and I want the call to define those places, while the function has only 2 variables for x and y. something like: Call("TargetFunction", ?? ) Func TargetFunction() Mouseclick($Xvar,$Yvar, bla bla bla) EndFunc Is there any way around this? I've searched here, after reading the help files, but couldn't work it out. . . Link to comment Share on other sites More sharing options...
Realm Posted November 28, 2010 Share Posted November 28, 2010 (edited) Hello DaRkf0x,You don't have to use variable for MouseClick(), you can use the actual values in those parameters. However if you prefer the variables due to your own custom function, than just change the variables before calling the funtionExamples:MouseClick('left',100,200) MouseClick('left',110,250) ;or for custom funtions: TargetFunction(100,200) Func TargetFunction($varX,$varY) MouseClick('left',$varX,$varY) Sleep(100) MouseClick('left',$varX+10,$varY+50) EndFuncRealm Edit: Fixed Typos Edited November 28, 2010 by Realm My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 28, 2010 Moderators Share Posted November 28, 2010 DaRkf0x,You need to use placeholder variables when you declare your function and then pass the real values in the function call. Here is a short example to show how it works:; Pass the vales 1 & 2 to the function and show the returned value $iReturn = _Add(1, 2) MsgBox(0, "Adding", "1 + 2 = " & $iReturn) ; Now 2 & 2 $iReturn = _Add(2, 2) MsgBox(0, "Adding", "2 + 2 = " & $iReturn) ; Then 3 & 2 $iReturn = _Add(3, 2) MsgBox(0, "Adding", "3 + 2 = " & $iReturn) ; And finally 4 & 2 $iReturn = _Add(4, 2) MsgBox(0, "Adding", "4 + 2 = " & $iReturn) ; Here is the function declaration - note the 2 placeholder variables Func _Add($iA, $iB) ; These placeholder variables hold the values we passed Local $iTotal = $iA + $iB ; So $iTotal is the sum of the values we passed - which we return to show that it worked Return $iTotal EndFuncNote that you do not have to use Call - just the function name will suffice. Please ask if you still are unclear. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
DaRkf0x Posted November 28, 2010 Author Share Posted November 28, 2010 I see whre you're getting, and so far I've understood it! Thank you both All I wanted to know was if I could assign a value to a variable while calling a function so that the variable will be used within the function with the value defined by the call. In that case all I have to do is add the variable to the function argument in - Function Target($var) - and define it when calling the function with - Call("Target",[value]) right? Also I came to realize I won't be needing a defined function for the particular case I'm analysing, but anyway it was a doubt I always add about Functions/Calls and it's now solved Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 28, 2010 Moderators Share Posted November 28, 2010 DaRkf0x, In that case all I have to do is add the variable to the function argument in - Function Target($var) - and define it when calling the function with - Call("Target",[value]) right?Yes, except as I mentioned above you do not need to use Call - just the function name will suffice as shown in the code I posted. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
DaRkf0x Posted November 28, 2010 Author Share Posted November 28, 2010 Ahhh I see that simplifies it even further I'm loving AutoIt more and more by the day Link to comment Share on other sites More sharing options...
SadBunny Posted November 28, 2010 Share Posted November 28, 2010 Ahhh I see that simplifies it even further I'm loving AutoIt more and more by the day Just to be complete: you would use Call if you have multiple functions and you want to use a variable to define the function to be performed... Something like: If $theWeatherIsGood Then $funcToCall = "sunshine" Else $funcToCall = "rain" EndIf Call($funcToCall) Exit Func sunshine() ; enjoy the beach EndFunc ;==>sunshine Func rain() ; enjoy the Internet from your warm, cozy home :) EndFunc ;==>rain Now this is actually a bad example, since in this case it would also be easier to directly call the functions: If $theWeatherIsGood Then sunshine() Else rain() EndIf ... so the bottomline is: if possible, avoid Call, not only because it is more characters of code but also because it limits your options. (Read the Call() help, it doesn't support ByRef parameter passing.) What is certain is that when you know exactly which function you want to call from which line of code, then you don't need Call. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
DaRkf0x Posted November 28, 2010 Author Share Posted November 28, 2010 Ah cool, so I can just use Target() instead of Call("Target"), that really saves a lot of code as in the script I'm making I tend to make a -lot- of calls. (I like to leave the code all neat and tidy and find that isolating it in functions, particularly when looping, is the best way to keep it simple and makes it easier to debug, for me) That really was helpful, thank you all (Now onto my other topic on GUI docking which isn't working ' ) 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