Jump to content
Sign in to follow this  

Gamebot for brick game lagging

Recommended Posts


I have tried to make a game bot as in lesson 10.

The code is here:

Global $Paused, $activeWindow, $winX, $winY

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

Dim $ballColor = 0x127D10

$Paused = True
$activeWindow = "the game window... Edited out"


$size = WinGetPos($activeWindow)
$winX = $size[0]
$winY = $size[1]
While 1

Func Game_Bot()
    While not $Paused
        $ball = PixelSearch( $winX-5, $winY+375, $winX+555, $winY+525, $ballColor, 50, 10) 
        If Not @error Then MouseClick("left", $ball[0], $ball[1], 1, 0)

Func TogglePause()
    $Paused = NOT $Paused

Func Terminate()
    Exit 0

but when I run this code it lags like hell and therefor doesnt work.. Can anyone tell me whats wrong? I have tried to minimize the area where it pixelssearch looks and also tried to make the colorspektrum wider and smaller.. Nothing seems to work.

Share this post

Link to post
Share on other sites

Increase the sleeps in your major loops.

To how much?? tried to increase it to 30 in the game loop.. didnt work..

Also if the sleep is too high I wont hit the ball.

And in the example script (lesson10) there is no sleep at all.

Share this post

Link to post
Share on other sites

Sleep() uses milliseconds so use what you wish, 100 is usually a nice number to start with, and work from there. 100 is 10 times a second.

I know its milliseconds.. And now I have tried everything from 5-200...

If it gets over 50 it cant catch the ball at all. At 20 it catches the ball most of the times but still misses.

And the lag is still there.. A lot.. I can see that the lag is causing the milliseconds to not be accurate.. At 20 milliseconds sleep there should be no visible lag as its 50 FPS if no lag. But it seems more like 15 FPS. The game is a simple java brick game in a browser. And when the script is off it runs smooth.

There must be something else wrong..

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  

  • Create New...