Jump to content

Gamebot for brick game lagging


bjarkekr
 Share

Recommended Posts

Hi!

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")
HotKeySet("{F9}","Game_Bot")

Dim $ballColor = 0x127D10

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

WinWaitActive($activeWindow)

$size = WinGetPos($activeWindow)
$winX = $size[0]
$winY = $size[1]
While 1
    ToolTip($Paused,0,0)
    Sleep(1000)
WEnd


Func Game_Bot()
    ToolTip('GAMEBOT',0,0)
    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)
        Sleep(1)
    WEnd
EndFunc

Func TogglePause()
    $Paused = NOT $Paused
EndFunc


Func Terminate()
    Exit 0
EndFunc

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.

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

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