Jump to content

Unlimited loops?


Recommended Posts

Heres my code

Global $loop2 = 1
Global $loop = 1
$GameTitle = "MyGame"
WinWaitActive($GameTitle)
Call("Gameloop")
Call("Gameloop2")

if $loop = 1 Then Gameloop() EndIf

Func Gameloop()
    $loop = $loop + 1
    ControlSend($GameTitle, "", "", "{SPACE}" )
    Sleep(10)
    Call("Gameloop")
EndFunc

if $loop2 = 100 Then Gameloop2() EndIf

Func Gameloop2()
    $loop2 = $loop2 - 1
    ControlSend($GameTitle, "", "", "{SPACE}" )
    Sleep(10)
    Call("Gameloop2")
EndFunc

Autoit does not like infinite loops. It gives an error and crashes after about 1 minute of this script running. So I tried to get it to go back and forth between two functions to no avail. Can anyone help me out here im sure its something simple. Thanks for the help!

Link to comment
Share on other sites

Global $loop2 = 1
Global $loop = 1
$GameTitle = "Game"
WinWaitActive($GameTitle)
Call("Gameloop")
Call("Gameloop2")

While $loop = 1 Then Gameloop()
    Wend
Func Gameloop()
    
    $loop = 1
    ControlSend($GameTitle, "", "", "{SPACE}" )
    Sleep(10)
    Call("Gameloop")

EndFunc

Like I said, still not working, any one else? Thanks for the help so far guys

Link to comment
Share on other sites

You syntax is truly odd.

Perhaps these will do something similar to what you may want.

A conditional while loop (infinite here) that performs operations on each loop

Global $loop=True
Global $GameTitle = "Game"
Global $ControlID = "Edit1"; change this!
WinWaitActive($GameTitle)
While $loop
    ControlSend($GameTitle, "", $ControlID, "{SPACE}" )
    Sleep(10)
;...
WEnd

or

A conditional while loop (infinite here) that executes a function on each loop

Global $loop=True
Global $GameTitle = "Game"
Global $ControlID = "Edit1"; change this!
WinWaitActive($GameTitle)
While $loop
    Function1()
;...
WEnd
Func Function1()
    ControlSend($GameTitle, "", $ControlID, "{SPACE}" )
    Sleep(10)
EndFunc

or

A while loop that completes a function before each loop and uses it's return value as the condition. (infinite here)

Global $loop=True
Global $GameTitle = "Game"
Global $ControlID = "Edit1"; change this!
WinWaitActive($GameTitle)
While Function1()
;do something else! :D
WEnd
Func Function1()
    Global $loop
    If Not $loop Then Return False
    ControlSend($GameTitle, "", $ControlID, "{SPACE}" )
    Sleep(10)
    Return True
EndFunc

All of which *should* be valid, but are useful under different conditions and each have their advantages depending on the situation.

I would probably suggest starting with the first example.

The last example is more useful for actually checking the outcome of a function for a condition - it doesn't really apply here.

Note 1: I didn't include anything to change $loop to false - and since you didn't indicate what your practical stopping conditions are, you'll be completing that part yourself.

Note 2: This also assumes you want to send to an actual control.

If you just want to send to a window without controls (like a game) you might consider Send(...)

If you want to set the text of a control (like an edit box), try ControlSetText(...).

Note 3:

There's no condition in these examples that checks whether the windows is STILL active

- you may find this necessary to add.

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Link to comment
Share on other sites

Well test this too.. just another variation of the examples posted here..

$GameTitle = "MyGame"
$ControlID = "Edit1"; change this!
WinWaitActive($GameTitle)

While 1
  ControlSend($GameTitle, "", $ControlID, "{SPACE}" )
  Sleep(10)
WEnd
Edited by snowmaker

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

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...