Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/22/2019 in all areas

  1. In this example:- The function IsArray1SomeInArray2() answers your first question of post #1. The function IsArray1InArray2() answers your second question of post #1. An optional case sensitivity parameter is added to answer one of my questions. #include <Array.au3> Local $sAlphabet = "ABCDEFGHIJKLMOPQRSTUVWXYZ" $aAlphabet = StringSplit($sAlphabet, "", 2) Local $sWord = "hello" ; "HELLO" ; "Hello" ; $aWord = StringSplit($sWord, "", 2) MsgBox(0, "IsArray1SomeInArray2()", "One or more of the elements of Array1" & (IsArray1SomeInArray2($aWord, $aAlphabet, 0) ? " are in " : " are NOT in ") & "Array2") MsgBox(0, "IsArray1InArray2()", "All the elements of Array1" & (IsArray1InArray2($aWord, $aAlphabet, 0) ? " are in " : " are NOT in ") & "Array2") ; Checks if some of the values from array1 ($word) are also in the array2 ($alphabet); also, ; Checks if some of the values from array1 ($alphabet) are also in the array2 ($word). Func IsArray1SomeInArray2($Array1, $Array2, $iCase = 0) ; $iCase = 0 (case insensitive, "h" = "H") $Array1 = _ArrayUnique($Array1, 0, 0, $iCase, $ARRAYUNIQUE_NOCOUNT) $Array2 = _ArrayUnique($Array2, 0, 0, $iCase, $ARRAYUNIQUE_NOCOUNT) Return UBound(StringRegExp(_ArrayToString($Array2), ($iCase ? "" : "(?i)") & _ArrayToString($Array1), 3)) > 0 EndFunc ;==>IsArray1SomeInArray2 ; Checks if all of the values from array1 ($word) are also in the array2 ($alphabet) Func IsArray1InArray2($Array1, $Array2, $iCase = 0) $Array1 = _ArrayUnique($Array1, 0, 0, $iCase, $ARRAYUNIQUE_NOCOUNT) $a = StringRegExp(_ArrayToString($Array2), ($iCase ? "" : "(?i)") & _ArrayToString($Array1), 3) Return UBound($Array1) = UBound($a) EndFunc ;==>IsArray1InArray2 If you do not understand something in either function, I suggest you use as many ConsoleWrite( [Insert variable here] & @CRLF)'s as needed, together with AutoIt's help file. Just as I have done, do, and will do. In SciTE, I use "cw ", that is, "cw" followed by a space - a shortcut.
    2 points
  2. El-Masry

    Function : _Loop_Task

    Hello every one, I wrote this function which can be used to do a task in the main loop without using : Sleep() inspired : https://www.autoitscript.com/forum/topic/198580-check-every-10sec-_imagesearch/ .... Here is the function : ;Timer_Task.au3 #include <Array.au3> #Region Example Local $counter = 1 While True _Loop_Task("_Test()", 1, 1000) ConsoleWrite("Counter: " & $counter & @CRLF) $counter += 1 Sleep(100) Wend Func _Test() MsgBox(0, 0, 0) EndFunc #EndRegion Example ; #FUNCTION# ===================================================================================================================== ; Name ..........: _Loop_Task ; Description ...: Doing a Task in the main loop without using Sleep() ; Syntax ........: _Loop_Task($Task, $Index, $MSEC_To_Wait) ; Parameters ....: $Task - A string of the task ..like this : "MsgBox(0, 0, 0)" ; $Index - A unique value which specifies the task , it is unique as 2 tasks can't have the same index ; $MSEC_To_Wait - the number of Milliseconds to wait...the task will be done every ($MSEC_To_Wait) Milliseconds ; Return values .: None ; Author ........: El-Masry : إبراهيم عصام الدين يوسف ; Email .........: iimosa7777@gmail.com ; Written in ....: ISN Autoit Studio ; With Example ..: Yes ; Inspired.......: https://www.autoitscript.com/forum/topic/198580-check-every-10sec-_imagesearch/ ; ================================================================================================================================ Func _Loop_Task($Task, $Index, $MSEC_To_Wait) ;note : #include <Array.au3> If IsDeclared("Task_Index_3425") == 0 Then Global $Task_Index_3425[] = [0] If _ArraySearch($Task_Index_3425, $Index) == -1 Then _ArrayAdd($Task_Index_3425, $Index) $Task_ID = _ArraySearch($Task_Index_3425, $Index) ;ConsoleWrite("Task ID = " & $Task_ID& @CRLF) If IsDeclared("Timer_Start_3425_" & $Task_ID) Then $M_Time = TimerDiff(Eval("Timer_Start_3425_" & $Task_ID)) ;ConsoleWrite("M_Time = " & $M_Time & @CRLF) If IsDeclared("Task_3425_" & $Task_ID) == 0 Then Assign("Task_3425_" & $Task_ID, 0, 2) ;ConsoleWrite("Waited Time = " & Eval("Task_3425_" & $Task_ID)& @CRLF) Assign("Task_3425_" & $Task_ID, Eval("Task_3425_" & $Task_ID) + $M_Time, 2) ;ConsoleWrite(Eval("Task_3425_" & $Task_ID)& @CRLF) If Eval("Task_3425_" & $Task_ID) >= $MSEC_To_Wait Then Execute($Task) Assign("Task_3425_" & $Task_ID, 0, 2) EndIf EndIf Assign("Timer_Start_3425_" & $Task_ID, TimerInit(), 2) EndFunc Have fun with it
    1 point
  3. It is good to want to improve upon the language; generally a good idea to become familiar with it first.
    1 point
  4. Also, you might consider cutting down your loop timing... if you Sleep(1000), your code just looks like a fancy message box Consider an example something a bit more like this: #Region Example Local $counter = 1 While True _Loop_Task("_Test()", 1, 1000) ConsoleWrite("Counter: " & $counter & @CRLF) $counter += 1 Sleep(100) Wend Func _Test() MsgBox(0, 0, 0) EndFunc #EndRegion Example Which shows your code being evaluated, but not executing the _Test function each loop
    1 point
  5. So out of curiosity, what does this buy someone rather than doing AdlibRegister?
    1 point
  6. it seems once a year we all gather to revisit this topic
    1 point
  7. An other way could be Scripting.Dictionary ;Local $sAlphabet = "ABCDEFGHIJKLMOPQRSTUVWXYZ" Local $sAlphabet = "ABCDEFGHIJKL" $aAlphabet = StringSplit($sAlphabet, "", 2) Local $sWord = "Hello" $aWord = StringSplit($sWord, "", 2) Local $sdAlphabet = ObjCreate("Scripting.Dictionary"), $count $sdAlphabet.CompareMode = 1 ; case insensitive For $i In $aAlphabet $sdAlphabet.Item($i) ; populate the dictionary Next For $i In $aWord If $sdAlphabet.Exists($i) Then $count += 1 ; then check Next Msgbox(0,"", $count & " values out of " & UBound($aWord) & " from $aWord exist in $aAlphabet")
    1 point
  8. Every function should return either a valid return or sets the @error.
    1 point
  9. Guess your clicker doesn't click faster than once per second and your "character" is killed by then? Jos
    1 point
  10. roselpi, Having now read back a bit more in the thread, I feel I must comment on this phrase from your last post: I am afraid that I do not agree with you here. You cannot expect AutoIt to provide functions that do exactly as you expect/wish in every case - it gives you a good set of basic commands which allow you to do practically anything with a bit of imagination and hard work. The UDFs we include with the standard AutoIt install are a good example of that - as the main author of the current _ArrayDisplay code I can assure you that its present behaviour is the result of many requests for an auto-expanding dialog, rather then the old fixed size one that used to be offered. My personal ExtMsgBox UDF that I suggested to you above is another case where basic AutoIt commands are combined to give you something much more polished than the basic Windows dialog. So what you are actually asking is for someone else to do all the hard work so that you can write a simple one-line command in your script which produces exactly what you require. Well, if that is not lazy - then I do not know what is! However, you finish with this line: And this is exactly what I would recommend. Take the existing _ArrayDisplay code (you actually need to look at ArrayDisplayInternals.au3) and try to understand what is going on within it - the code is actually pretty well commented for a standard UDF which will help enormously. You should then be able to write your version, omitting or changing various sections to get precisely what you want. I am certain people here will offer help on any questions you might have - as long as you have done due diligence with the Help file and forum search facility beforehand. That is the best way to learn AutoIt - getting down and dirty with the code. M23
    1 point
×
×
  • Create New...