9 posts in this topic
As with a lot of programming, the less manual repetition done to achieve the same outcome...the better.
I package programs for network deployment at the organization I work for. Sometimes these applications require verbose messaging to the user, and sometimes by special request we have to turn that off and deploy silently.
The way I currently handle these 2 scenarios is this.
I have a function that builds the splashwin display screen to variable size depending on message length, and displays the desired message to the end user.
Then at each point throughout my script as I need to make the user aware of what is currently happening, I inject a splashwin function call with the unique message pertaining to that specific event. ie. "Installing Microsoft Office, please wait..."
In effort to build a more universal script to handle any type of request submitted. I've incorporated a switch command of '/silent'
If cmdlineraw detects the usage of that switch when the script is triggered it sets a variable flag, ie. $silent = "on"
Then at every splashwin call I make, I'm prefixing it with an IF statement that checks for the flag, and then does NOT display the message if that flag is "on". Or does display it if its not. Has worked for me just fine. But while I grow my programming skills and look for more streamlined ways of handling areas I find myself creating repetition. I'm curious if I can relocate that flag check. Taking it out of every single splashwin call, and injecting it into the function itself.
Example of how I currently display or hide the splashwin based on command line...
If StringInStr($cmdlineraw, "/silent", 0) Then
$SilentSwitch = "ON"
If $SilentSwitch = "OFF" Then SplashWin($Uninstalling & $ProductInfo)
Some scripts have dozens of those splashwin calls littered throughout, so Is this the best approach I can take already? Or as stated earlier, can I pull the IF statement away from the splashwin call. And left the function as a whole either activate or deactivate as a result of the command line check.
Edit: Just realised this was posted in the wrong forum! I guess the Mods will move it to either "AutoIt General Help and Support" or "AutoIt Technical Discussion".
Do you use type checking? Or do you choose not to type check?
I was trying to think of the simplest way to do a type check without typing arguments more than once and I came up with:
Func displayPerson($firstName, $lastName, $age) ; -- TYPE CHECK -- Local $typeCheck = ("" _ & IsString($firstName) _ & IsString($lastName) _ & IsNumber($age) _ ) If (StringInStr($typeCheck, "0")) Then MsgBox(16, "Type Error: displayPerson()", $typeCheck) ; -- FUNCTION -- MsgBox(0, "", $firstName & " " & $lastName & " (" & $age & ")") EndFunc The only catch with this method is that it produces a very simplistic error message. Even still, the fact that you only have to type out arguments once makes it a reasonable approach, in my opinion. The same logic can also be used for making function contracts (for example: $firstName mustn't be an empty string etc...).
What do you think? How do you go about such things?
I've ported these two functions from PHP to AU3 to work with URLs.
Made them for those who work with libraries like HTTP.au3 (not the one I coded), that needs passing the server domain, path, etc., instead of the full URL.
Grab the lib here.
ParseURL( $sURL )
Parses the URL and splits it into defined parts. Returns an array:
 = Full URL (same as $sURL)  = Protocol (i.e.: http, https, ftp, ws...)  = Domain  = Port (or null if not specified)  = Path (or null if not specified)  = Query string (everything after the ? - or null if not specified) Example:
$aExample = ParseURL("https://google.com:8080/?name=doe") MsgBox(0, "Test", "URL: " & $aExample & @CRLF & _ "Protocol: " & $aExample & @CRLF & _ "Domain: " & $aExample & @CRLF & _ "Port: " & $aExample & @CRLF & _ "Path: " & $aExample & @CRLF & _ "Query string: " & $aExample)
ParseStr( $sStr )
Parses a query string (similar to the  of the previous function) and returns a multidimensional array, where:
 = number of variables found  = ununsed  = key name of the first variable  = first variable value (already URL decoded) [n] = key name of the nth variable [n] = nth variable value (already URL decoded) Example:
include <Array.au3> ; need only to do _ArrayDisplay, not needed by the lib _ArrayDisplay(ParseStr("foo=bar&test=lol%20123")) #cs Result is:  = 2  = ununsed  = foo  = bar  = test  = lol 123 #ce Feel free to fork!
I am trying to allow the GUI to gather info as to when to execute a function. I am having trouble doing this. So far this is what I have.
;Timer Func timer () If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(36,"Timer","Please format your answer in 00:00:00:000") Select Case $iMsgBoxAnswer = 6 ;Yes Global $infotime = InputBox ('Time', 'What time to execute?') Do $rawtimer = ToolTip(@Hour & ':' & @Min & ':' & @Sec & ':' & _MSec()) until $rawtimer = $infotime if $rawtimer = $infotime Then msgbox (0,'Worked','Worked') Else EndIf Case $iMsgBoxAnswer = 7 ;No Exit EndSelect EndFunc Func _MSec() Local $stSystemTime = DllStructCreate('ushort;ushort;ushort;ushort;ushort;ushort;ushort;ushort') DllCall('kernel32.dll', 'none', 'GetSystemTime', 'ptr', DllStructGetPtr($stSystemTime)) $sMilliSeconds = StringFormat('%03d', DllStructGetData($stSystemTime, 8)) $stSystemTime = 0 Return $sMilliSeconds EndFunc I have also tried _GUIToolTip_GetText in order to read the tooltip until the time specified, but it still doesn't work. Any help would be great.
im some what new to autoit and need help figuring out best way to make a simple clicker for few idle games i play(taptitdue, sakura clicker, elndless frontier etc.) ive played around with autoit recorder to make simple copy mouse clicks. but now i want to make a script that allows me to select multiple functions before starting the script for game ex: click section A or click section A + B to run At set intervals if that makes sense . i dont need scripts made by other just info on what things i should use to make it my self.
need to be able to select between games and be able to select multiple functions to run inconjuntion or independent for each game. thank you in advance