Sign in to follow this  
Followers 0
f0xh4x0r

Unlimited loops?

8 posts in this topic

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!

Share this post


Link to post
Share on other sites



That's not an infinite loop, that's an infinite recursion which makes every language error out sooner or later.

Try 'While' instead.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Recursion level exceeded still not working. Any other ideas?

Edited by f0xh4x0r

Share this post


Link to post
Share on other sites

Yes. Use a while loop like monoceres said.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Thank you so much for that, when I get home I will test those scripts and let you know what happens!

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0