Sign in to follow this  
Followers 0
Kitsune

Script Lag Issues

1 post in this topic

I've been noticing severe lag in this script that I've been working on to become familiar with AutoIt, I have my suspicions that it is due to an API overhead. I already know which sections of the code are suffering from lag, Debug sections 1,2,3, & 7.

CODE
#include <Misc.au3>

;$dll = Dllopen("dwmapi.dll")

;Dllcall($dll,"int","DwmEnableComposition","dword","DWM_EC_DISABLECOMPOSITION")

Opt('MouseCoordMode',2)

Opt('PixelCoordMode',2)

Opt("MouseClickDragDelay",0)

HotKeySet('{F6}','_Start')

Global $Run = 0

Global $Level = 1

Global $TempleBuilt=false

Global $ArcheryBuilt=false

Global $DemoLabBuilt=false

Global $WorkshopBuilt=false

Global $ManapoolBuilt=false

Global $ConvertNext=0

Global $ConvertTimer

Global $Recruits = 0

Global $Dispense=1

Global $BombTimer

Global $DebugTimer

Global $DebugTimer2

Global $DebugCount=0

Global $Debug0=0

Global $Debug1=0

Global $Debug2=0

Global $Debug3=0

Global $Debug4=0

Global $Debug5=0

Global $Debug6=0

Global $Debug7=0

$oGame = ObjCreate ("ShockwaveFlash.ShockwaveFlash.1")

$Form1 = GUICreate("", 560, 410, -1, -1)

$GUIActiveX = GUICtrlCreateObj ($oGame, 5, 5, 550, 400)

GUISetState()

With $oGame

.bgcolor = "#000000"

.Movie = 'http://www.xgenstudios.com/castle/castlexgen.swf'

.ScaleMode = 1

.Loop = True

.wmode = "Opaque"

EndWith

$Pause = 1

While 1

$Msg = GUIGetMsg()

Switch $Msg

Case -3

Exit

EndSwitch

Sleep(10)

WEnd

Func _Start()

If $Run = 1 Then

$Run = 0

Return

Else

$Run = 1

ConsoleWrite('Starting----------------------' & @CRLF)

EndIf

WinSetTitle($Form1, '', 'Level: ' & $Level & ' - Recruits: ' & $Recruits)

MouseMove(50, 255,10)

MouseMove(295, 255,10)

MouseMove(295, 335,10)

MouseMove(50, 335,10)

MouseMove(50, 255,10)

While $Run

If Not _IsPressed("11") Then

Sleep(9)

$Debug0 += TimerDiff($DebugTimer)

If Not $DebugCount Then

Tooltip($Debug0/20 & @CRLF & $Debug1/20 & @CRLF & $Debug2/20 & @CRLF & $Debug3/20 & @CRLF & $Debug4/20 & @CRLF & $Debug5/20 & @CRLF & $Debug6/20 & @CRLF & $Debug7/20,40, 30)

$Debug0=0

$Debug1=0

$Debug2=0

$Debug3=0

$Debug4=0

$Debug5=0

$Debug6=0

$Debug7=0

$DebugCount=20

Else

$DebugCount -= 1

EndIf

$DebugTimer=TimerInit()

$DebugTimer2=TimerInit()

$Coords = PixelSearch(220, 285, 310, 315, 0x000000, 19)

If NOT @error Then

If $ConvertNext=0 Then

If TimerDiff($BombTimer) > 5000 Then

If PixelGetColor(286,65) = 16763904 Then

;MouseClick('left',285, 65,1,0)

Send("2")

MouseClick('left', $Coords[0] , $Coords[1], 1, 0)

MouseMove(40, 30,0)

;Sleep(25)

EndIf

$BombTimer=TimerInit()

Else

_MouseClickDrag("left",$Coords[0],$Coords[1],40, 30,0)

EndIf

Else

$ConvertNext=0

_MouseClickDrag("left",$Coords[0],$Coords[1],365, 200,0)

$ConvertTimer=TimerInit()

EndIf

EndIf

Sleep(5)

$Debug1 += TimerDiff($DebugTimer2)

$DebugTimer2=TimerInit()

$Coords = PixelSearch(50, 200, 310, 300, 0xFFFFFF, 0, 2)

If Not @error Then

If PixelGetColor(258,62) = 13369344 Then

;MouseClick('left',265, 65,1,0)

Send("1")

MouseClick('left', $Coords[0] , $Coords[1], 1, 0)

MouseMove(40, 30,0)

;Sleep(25)

EndIf

EndIf

Sleep(5)

$Debug2 += TimerDiff($DebugTimer2)

$DebugTimer2=TimerInit()

$Coords = PixelSearch(50, 285, 330, 325, 0x6A0000, 5, 5)

If Not @error Then

;If PixelGetColor(258,62) = 13369344 Then

;MouseClick('left',265, 65,1,0)

;Send("1")

MouseClick('left', $Coords[0] , $Coords[1], 1, 0)

MouseMove(40, 30,0)

;Sleep(25)

;EndIf

EndIf

Sleep(5)

$Debug3 += TimerDiff($DebugTimer2)

$DebugTimer2=TimerInit()

If $TempleBuilt And Not $ConvertNext Then

If $Recruits < 10 Then

If TimerDiff($ConvertTimer) > 1000 Then

$pix = PixelGetColor(365,10)

;PixelSearch(365,10,366,11,0x95D6F9,3);sky

If $pix = 9819897 Then

$ConvertNext=1

$Recruits = _CountRecruits()

WinSetTitle($Form1, '', 'Level: ' & $Level & ' - Recruits: ' & $Recruits)

ElseIf $pix = 16777215 Then

;PixelSearch(365,10,366,11,0xFFFFFF,3);cloud

;If NOT @error Then $ConvertNext=1

$ConvertNext=1

$Recruits = _CountRecruits()

WinSetTitle($Form1, '', 'Level: ' & $Level & ' - Recruits: ' & $Recruits)

EndIf

EndIf

EndIf

EndIf

Sleep(5)

$Debug4 += TimerDiff($DebugTimer2)

$DebugTimer2=TimerInit()

If $Recruits > 5 Then

If $Level < 14 Then

If $ManapoolBuilt Then

$Coords = PixelSearch(215, 5,280, 155,0xFFFF75,5)

If NOT @error Then

MouseClick("left",$Coords[0],$Coords[1],1,0);build mage, no matter how tall the castle

MouseMove($Coords[0],$Coords[1],0)

$Recruits = _CountRecruits()

EndIf

EndIf

Else

If $Dispense = 0 Then

If $WorkshopBuilt Then

$Coords=PixelSearch(215, 5,550,365,0x35E201,5)

If NOT @error Then

MouseClick("left",$Coords[0],$Coords[1],1,0);build repairman, no matter how tall the castle

MouseMove($Coords[0],$Coords[1],0)

$Recruits = _CountRecruits()

EndIf

EndIf

$Dispense += 1

ElseIf $Dispense = 1 Then

If $ArcheryBuilt Then

$Coords=PixelSearch(215, 5,550,365,0xF66262,5)

If NOT @error Then

MouseClick("left",$Coords[0],$Coords[1],1,0);build archer, no matter how tall the castle

MouseMove($Coords[0],$Coords[1]+20,0)

$Recruits = _CountRecruits()

EndIf

EndIf

$Dispense += 1

Else

If $ManapoolBuilt Then

$Coords = PixelSearch(215, 5,280, 155,0xFFFF75,5)

If NOT @error Then

MouseClick("left",$Coords[0],$Coords[1],1,0);build mage, no matter how tall the castle

MouseMove($Coords[0],$Coords[1],0)

$Recruits = _CountRecruits()

EndIf

EndIf

$Dispense = 0

EndIf

WinSetTitle($Form1, '', 'Level: ' & $Level & ' - Recruits: ' & $Recruits)

EndIf

EndIf

Sleep(5)

$Debug5 += TimerDiff($DebugTimer2)

$DebugTimer2=TimerInit()

$Coords = PixelSearch(50, 285, 255, 315, 0x001300, 2,3)

If @error Then

_CheckState()

ContinueLoop

EndIf

$Debug6 += TimerDiff($DebugTimer2)

$DebugTimer2=TimerInit()

If NOT @error Then

If PixelGetColor(314,59) = 52479 Then

;MouseClick('left',285, 65,1,0)

Send("3")

MouseClick('left', $Coords[0] , $Coords[1], 1, 0)

MouseMove(40, 30,0)

;Sleep(9)

$Recruits = _CountRecruits()

WinSetTitle($Form1, '', 'Level: ' & $Level & ' - Recruits: ' & $Recruits)

ElseIf $ConvertNext=0 Then

_MouseClickDrag("left",$Coords[0],$Coords[1],40, 30,0)

Else

$ConvertNext=0

_MouseClickDrag("left",$Coords[0],$Coords[1],365, 200,0)

$ConvertTimer=TimerInit()

EndIf

EndIf

Sleep(5)

$Debug7 += TimerDiff($DebugTimer2)

Else

Sleep(200)

EndIf

WEnd

EndFunc

Func _CheckState()

If PixelGetColor(8,8) = 0 Then

Local $s_Cursor = MouseGetCursor()

MouseMove(365, 365)

Do

Sleep(10)

Until MouseGetCursor() <> $s_Cursor

Sleep(250)

MouseClick('left')

Switch $Level

Case 6

MouseClick('left', 385, 105)

$TempleBuilt = True

Case 11

MouseClick('left', 385,310)

$ManapoolBuilt = True

MouseClick('Left',165, 280,Floor($Level/4),0)

MouseClick('left', 385,260)

Case 16

MouseClick('left', 385,155)

$TempleBuilt = False

$ConvertNext = False

Case Else

If Hex(PixelGetColor(245, 25),6) <> 'D90000' Then

$looptime = TimerInit()

Do

MouseClick('left',170, 140,1,0)

Sleep(10)

If TimerDiff($looptime)>5000 Then ;tests for potentially harmful infinite mouseclick loop and stops it

ExitLoop

EndIf

Until Hex(PixelGetColor(245, 25),6) = 'D90000'

EndIf

If $Level > 12 Then

MouseClick('Left',165, 280,Floor($Level/4),0)

EndIf

EndSwitch

Sleep(750)

MouseClick('left', 505, 375)

While PixelGetColor(8,8) = 0

Sleep(10)

WEnd

$Level += 1

WinSetTitle($Form1, '', 'Level: ' & $Level & ' - Recruits: ' & $Recruits)

$Coords = PixelSearch(215, 5,280, 155,0xFFFF75,5)

If NOT @error Then

$ManapoolBuilt=True

EndIf

$Coords=PixelSearch(215, 5,550,365,0xF66262,5)

If NOT @error Then

$ArcheryBuilt=True

EndIf

$Coords=PixelSearch(215, 5,550,365,0x35E201,5)

If Not @error Then

$WorkshopBuilt=True

EndIf

Return

EndIf

EndFunc

Func _MouseClickDrag($s_Button, $s_X1,$s_Y1, $s_X2,$s_Y2,$s_Speed)

MouseMove($s_X1, $s_Y1,$s_Speed)

MouseDown($s_Button)

;Sleep(5)

MouseMove($s_X2, $s_Y2,$s_Speed)

Sleep(8)

Sleep(8)

Sleep(8)

MouseUp($s_Button)

Return

EndFunc

Func _CountRecruits()

Local $s_Rec = 0

Local $x

For $x = 0 To 10

If PixelGetColor(355+(18*$x), 45) = 52479 Then

$s_Rec += 1

EndIf

Next

Return $s_Rec

EndFunc

I would appreciate if anyone is able to discern a way to reduce or eliminate this significant lag(highest total lag average that I've noted was in the 60K ms range at roughly level 25 and higher).

This script is designed for a single-player flash game.

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