Sign in to follow this  
Followers 0
Dgameman1

How can I make my script wait for a color to appear?

11 posts in this topic

I want my script to wait until a color appears before doing anything else using pixelsearch?

Share this post


Link to post
Share on other sites



Never worked with PixelSearch before, but I think something like this would probably do it:

Do
PixelSearch(blah blah blah)
Until Pixelsearch(blah blah blah) NOT @error
1 person likes this

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

Never worked with PixelSearch before, but I think something like this would probably do it:

Do
PixelSearch(blah blah blah)
Until Pixelsearch(blah blah blah) NOT @error

Works perfectly thank you. Now, is it possible to make it until for the color to appear FOR a certain amount of time, and if it doesn't appear within that amount of them, then it just continues through the thread instead of endlessly waiting?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Add a timer:

$ExitTime = 5000 ;In Miliseconds, 5 seconds
$Time = TimerInit ()
Do
     PixelSearch(blah, blah, blah)
Until PixelSearch(blah, blah, blah) Not @Error Or TimerDiff($Timer) >= $ExitTime
Edited by LurchMan

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites

I have a problem

This is my code

$start = timerinit()
Do
   $coord=PixelSearch ( 157, 98, 225, 146, 0x545453 , 0 , 1, ""  )
   $diff = timerdiff ($start)
  Until not @error  OR $diff > 10000
  MouseMove ( $coord[0], $coord[1] )
    msgbox(32,"gtfds","gfds")

And it just ends about a second after I run it. What's the problem?

Share this post


Link to post
Share on other sites

Do
If Not WinActive($hwnd_Window) Then
WinActivate($hwnd_Window)
WinWaitActive($hwnd_Window)
EndIf
GUI()
Sleep(5)
$aPosition = PixelSearch($Left, $Top, $Right, $Bottom, $Red, $RedColorSensitivity, 3)
CheckTimer(@error)
Until @error <> 1
If IsArray($aPosition) Then
MouseMove($aPosition[0] + Random(-5, 5, 1), $aPosition[1] + Random(-3, 3, 1), 5)
$SLeft = $aPosition[0] - 50
$SRight = $SLeft + 60
$STop = $aPosition[1] - 50
$SBottom = $STop + 65
EndIf

Func CheckTimer($PixelError)
If TimerDiff($Timer) >= $MaxTime Then
SetError(0)
Return -1
EndIf
SetError($PixelError)
EndFunc ;==>CheckTimer


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

Do
If Not WinActive($hwnd_Window) Then
WinActivate($hwnd_Window)
WinWaitActive($hwnd_Window)
EndIf
GUI()
Sleep(5)
$aPosition = PixelSearch($Left, $Top, $Right, $Bottom, $Red, $RedColorSensitivity, 3)
CheckTimer(@error)
Until @error <> 1
If IsArray($aPosition) Then
MouseMove($aPosition[0] + Random(-5, 5, 1), $aPosition[1] + Random(-3, 3, 1), 5)
$SLeft = $aPosition[0] - 50
$SRight = $SLeft + 60
$STop = $aPosition[1] - 50
$SBottom = $STop + 65
EndIf
 
Func CheckTimer($PixelError)
If TimerDiff($Timer) >= $MaxTime Then
SetError(0)
Return -1
EndIf
SetError($PixelError)
EndFunc ;==>CheckTimer

I dun understand =[[

Share this post


Link to post
Share on other sites

Do
    $coord = PixelSearch(157, 98, 225, 146, 0x545453, 0, 1, "")
    $diff = TimerDiff($start)
Until Not @error Or $diff > 10000

I am not sure about this... @error can be setted by the TimerDiff function so is useless, in this case you should use this

Do
    $coord = PixelSearch(157, 98, 225, 146, 0x545453, 0, 1, "")
    $diff = TimerDiff($start)
Until IsArray($coord) Or $diff > 10000

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I dun understand =[[

Then learn. The code I posted is from an operational program that I use at least once a week. It works exactly as advertised and does exactly what you're asking for. We're not here to write the bot* you want for you. We're not here to spoon feed you code. You can take what I posted apart line by line and learn what's going on, how the programming logic works, and cross reference it with the help file, or you can sit there and twiddle your thumbs and go nowhere.

*Because that's what 99% of the pixelsearch questions boil down to. Game automation.

Edited by Blue_Drache
1 person likes this

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

Then learn. The code I posted is from an operational program that I use at least once a week. It works exactly as advertised and does exactly what you're asking for. We're not here to write the bot* you want for you. We're not here to spoon feed you code. You can take what I posted apart line by line and learn what's going on, how the programming logic works, and cross reference it with the help file, or you can sit there and twiddle your thumbs and go nowhere.

*Because that's what 99% of the pixelsearch questions boil down to. Game automation.

Sorry about that, I didn't exactly look at it before, I kinda looked at it and said to myself womfg too much code.

But now that I look at it, I just used the help file for stuff I didn't know. and it actually does exactly what I want it to do lol

THanks =P

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