Jump to content

Simultaneous Loops


Recommended Posts

How do I run two loops simultaneously and independently?

This Script

WinWait("Nomad", "")
       If Not WinActive("Nomad", "") Then WinActivate("Nomad", "")
       WinWaitActive("Nomad", "")
       Sleep(10000)
       MouseClick("left")
       If Random(0, 1, 1) Then
           MouseClick("left", 990, 155, 1) 
       Else     
           MouseClick("left", 910, 155, 1) 
       EndIf
       MouseClick("left")

And This Script

WinWait("Nomad", "")
       If Not WinActive("Nomad", "") Then WinActivate("Nomad", "")
       WinWaitActive("Nomad", "")
       Sleep(400)
       $ColorHP = PixelGetColor(179, 36)
       $ColorMP = PixelGetColor(160, 56)
       $ColorHP2 = PixelGetColor(154, 36)
       If $ColorMP = 592137 Then
          $ColorMP = 0
          Send("{9 1}")
          Sleep(100)
          Send("{T 1}")
          Sleep(100)
          Send("{0 1}")
          Sleep(100)
       EndIf
       If $ColorHP2 = 592137 Then
          $ColorHP2 = 0
          Send("{R 1}")
          Sleep(100)
       EndIf
       If $ColorHP = 592137 Then  ;Checking For low HP in deciaml not hexa.
          $ColorHP = 0        
          Send("{4 1}")
          Sleep(200)
          Send("{4 2}")
          Sleep(600)
       If $ColorMP = 592137 Then
          $ColorMP = 0
          Send("{Q 1}")
       EndIf        
      Else
          Sleep(200)
          Send("{` 3}")
          Send("{Space 2}") ;use to auto fight pressing Space, 2 times
          Sleep(1000)
          Send("{1 2}")
          Sleep(200)
          Send("{` 3}")  
       EndIf
Edited by Fumbles
Link to comment
Share on other sites

AutoIt is not multithreaded so that is not possible. There is 2 solutions:

  • Use 2 separate scripts
  • Merge your code into 1 "loop"
BTW there isn't a single loop in that code, you really should try to ask questions that makes sense to OTHER people, not just your own twisted mind >_<
Link to comment
Share on other sites

Is this some sort of game bot? >_<

But as AdmiralAlkex said neither of these are *loops and autoit is not capable of running *two loops simultaneously in the sense you are trying to accomplish.

Once you get them as loops, just make them separate programs and choose one or the other and make it automatically open the other script when you start the first one.

Script One Starts

Script One Opens Script Two

Both Scripts Enter and Run Loops.

$Script2 = @ScriptDir & '\script2.exe'
ShellExecute($Script2)

* = Failed at typing first time around.

Edited by Rydextillxixdiex

...will never learn all there is to know about autoit, no worries...i came to the forums :)

Link to comment
Share on other sites

Or you could try my overly complicated idea of creating a scheduler for autoit. Obviously you could automate the function creation.

;;[#][0] = name
;[#][1] = length
;[#][2] = next step, start at 1
;[#][3] = while currently in
Global $functions[2][4]
$functions[0][0] = "counterEven"
$functions[1][0] = "counterOdd"
$functions[0][1] = 4
$functions[0][2] = 1
$functions[0][3] = 0
$functions[1][1] = 4
$functions[1][2] = 1
$functions[1][3] = 0


_scheduler()

;========================
;===== functions to run =
;========================

Func counterEven()
    $i = 0
    While 1
        ConsoleWrite($i & @CRLF)
        Sleep(1000)
        $i += 2
    WEnd
EndFunc   ;==>counterEven


Func counterOdd()
    $i = 1
    While 1
        ConsoleWrite($i & @CRLF)
        Sleep(1000)
        $i += 2
    WEnd
EndFunc   ;==>counterOdd


;===============================
;====== scheduler ==============
;===============================

Func _scheduler()

    While 1
        For $i = 0 To 1
            If Call($functions[$i][0] & "_numberof_while") > 0 Then ;checks to see if while loops
                If Call($functions[$i][0] & "_while_1_start") = $functions[$i][2] - 1 And Call($functions[$i][0] & "_while_1") = True Then $functions[$i][3] = 1 ;puts in while # 1
                If Call($functions[$i][0] & "_while_1_end") = $functions[$i][2] - 1 And Call($functions[$i][0] & "_while_1") = True Then $functions[$i][2] = Call($functions[$i][0] & "_while_1_start") + 1 ;sends to begining of while
            EndIf

            Call($functions[$i][0] & "_" & $functions[$i][2])
            $functions[$i][2] += 1
        Next
    WEnd

EndFunc   ;==>_scheduler




;===============================
;====== Broken Down function ==
;===============================

Func counterEven_numberof_while()
    Return 1
EndFunc   ;==>counterEven_numberof_while

Func counterEven_while_1()
    Return 1 ; the value from the first while
EndFunc   ;==>counterEven_while_1

Func counterEven_while_1_start()
    Return 1 ; the command it starts AFTER
EndFunc   ;==>counterEven_while_1_start

Func counterEven_while_1_end()
    Return 4 ;the command the wend is AFTER
EndFunc   ;==>counterEven_while_1_end

Func counterEven_0()
    ;blank func
EndFunc   ;==>counterEven_0

Func counterEven_1()
    Global $counterEven_var1 = 0
EndFunc   ;==>counterEven_1

Func counterEven_2()
    ConsoleWrite($counterEven_var1 & @CRLF)
EndFunc   ;==>counterEven_2

Func counterEven_3()
    Sleep(1000)
EndFunc   ;==>counterEven_3

Func counterEven_4()
    $counterEven_var1 += 2
EndFunc   ;==>counterEven_4




Func counterOdd_numberof_while()
    Return 1
EndFunc   ;==>counterOdd_numberof_while

Func counterOdd_while_1()
    Return 1 ; the value from the first while
EndFunc   ;==>counterOdd_while_1

Func counterOdd_while_1_start()
    Return 1 ; the command it starts AFTER
EndFunc   ;==>counterOdd_while_1_start

Func counterOdd_while_1_end()
    Return 4 ;the command the wend is AFTER
EndFunc   ;==>counterOdd_while_1_end

Func counterOdd_0()
    ;blank func
EndFunc   ;==>counterOdd_0

Func counterOdd_1()
    Global $counterOdd_var1 = 1
EndFunc   ;==>counterOdd_1

Func counterOdd_2()
    ConsoleWrite($counterOdd_var1 & @CRLF)
EndFunc   ;==>counterOdd_2

Func counterOdd_3()
    Sleep(1000)
EndFunc   ;==>counterOdd_3

Func counterOdd_4()
    $counterOdd_var1 += 2
EndFunc   ;==>counterOdd_4

Yes, I know there are much easier ways to do it. But this attempts to divide up the process as a single cored processor would. Using a scheduler to distribute processing time.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...