IAMK Posted August 15, 2018 Share Posted August 15, 2018 I had a few ideas to make writing scripts easier and cleaner. However, this will be done through creating functions to call a function which already exists. Is this a stupid idea? Or is the benefit to development better than the loss to functionality? Note: At any time, I could just use the default function. E.g. The left side will call a function which will execute the right side. Click($x, $y) = MouseClick("Primary", $x, $y, 1, 0) Click("Help") = MouseClick("Primary", $helpX, $helpY, 1, 0) ;$helpX and $helpY would be predefined in the function's file. E.g. position of the help button. TT($msg) = ToolTip($msg, 0, 0) TT($msg, 1) = ToolTip($msg) ;location of cursor Inc($var) = ($var = $var + 1) Check("Help") = (PixelGetColor($helpX, $helpY) = $helpColor) ;the color of the help button when it is available will be predefined in the function's file. Then, instead of code like this: While(PixelGetColor(250, 100) = 13547645) If(PixelGetColour(300, 150) = 15245343) Then MouseClick("Primary", 300, 150, 1, 0) ToolTip("Clicked 300, 150", 0, 0) Sleep(100) EndIf WEnd It would become: While(Check("Help")) If(Check("Continue")) Then Click(300, 150) TT("Clicked 300, 150") Sleep(100) EndIf WEnd Also, the plan is to have all the predefined things, e.g. $helpX, $helpY and $helpColor, in the function file, so that all my scripts can #include it. Then, if any of the variables' values ever change, I can just change the 1 file and build all my scripts again. Is this what I should be doing? I believe it will make development, and even more, maintenance, much easier. However, this unnecessarily duplicates function calls, so is it worth implementing? Also, if I do implement this, should I have every overloaded function in 1 file? (Assume I have 50+) Or should I group them and have 5 per file so that I don't #include every function and their moms when not needed? Thank you in advance. Link to comment Share on other sites More sharing options...
jdelaney Posted August 15, 2018 Share Posted August 15, 2018 (edited) You will kill the intelisense. ..the part that pops up and tells you what variable does what while typing in scite . you can add in your function to do the same, but that requires edits to files in each developer station. I don't see a point in creating any function that only does one thing. ..why not just call that one wrapped function to begin with? Edited August 15, 2018 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
BrewManNH Posted August 15, 2018 Share Posted August 15, 2018 37 minutes ago, jdelaney said: I don't see a point in creating any function that only does one thing. That's called Functional programming, each function does one thing, and if you need it to do more, you have it call the other helper functions that do that. Keeps you from recreating code inside functions that already exist elsewhere, and allows your code to be modular. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
IAMK Posted August 15, 2018 Author Share Posted August 15, 2018 3 hours ago, jdelaney said: why not just call that one wrapped function to begin with? I'm not sure what this means. Could you please explain? 2 hours ago, BrewManNH said: allows your code to be modular. This is the goal, because currently, my boss asks for 1 script, then another, and another. Each script is basically a few changes to previous existing scripts. With modules, I can choose which things I want and basically just plug them into my code where needed. Link to comment Share on other sites More sharing options...
jdelaney Posted August 15, 2018 Share Posted August 15, 2018 (edited) 5 hours ago, BrewManNH said: That's called Functional programming, each function does one thing, and if you need it to do more, you have it call the other helper functions that do that. Keeps you from recreating code inside functions that already exist elsewhere, and allows your code to be modular. I understand this, but for what he's doing, there is no code, or recurring script. He is taking a function, and doing nothing more than wrapping his own function around it. I suppose this allows you, in the future, to then make a change in your function that would be done every time it was called, but at this point, it seems like needless overhead: Func TT($s) ToolTip($s) EndFunc If you planned on doing at least two things, then sure, wrap away...do you want the tooltip right where your mouse is everytime? That makes sense to wrap: Func TT($s) Local $a = MouseGetPos() If IsArray($a) Then ToolTip($s, $a[0], $a[1]) Else ToolTip($s) EndIf EndFunc You can create your own repository of functions that you call, by using #include. #include https://www.autoitscript.com/autoit3/docs/keywords/include.htm Then, you just include that file, and you can have a shared set of functions. Edited August 16, 2018 by jdelaney Xandy 1 IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
junkew Posted August 16, 2018 Share Posted August 16, 2018 Assigning function to var could also be helpfull as you then later can implement it by just pointing the var to a different function. $tt=tooltip FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
IAMK Posted August 16, 2018 Author Share Posted August 16, 2018 Okay, I will try that. Thank you. 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