lilandywandy Posted July 17, 2005 Posted July 17, 2005 this is the script that i have: $Temp = 0 While 1 If PixelGetColor(367,708) <> Dec(0x00f742) Then If $Temp = 0 Then $Timer = TimerInit() EndIf $Temp = 1 If TimerDiff($Timer) > 12000 Then Send("{ESC}") Else $Temp = 0 EndIf Wend what im trying to do is make a program so that, "when 367,708 has not been 00f742 for 12 secs straight, then press esc". right now, this script seems to just send esc after 12 secs when it is started
Valuater Posted July 18, 2005 Posted July 18, 2005 (edited) $Temp = 0 While 1 If PixelGetColor(367,708) = Dec(0x00f742) Then $Temp = 0 EndIf If Not PixelGetColor(367,708) = Dec(0x00f742) Then $Temp = $Temp +1 If $Temp = 12 then Send("{ESC}") $Temp = 0 Endif EndIf Sleep(1000) ; sleep 1 second Wend ****** I cant test this **** but it should help 8) Edited July 18, 2005 by Valuater
herewasplato Posted July 18, 2005 Posted July 18, 2005 $Temp = 0 Do If PixelGetColor(367,708) = Dec(0x00f742) Then $Temp = 0 Else $Temp = $Temp + 1 EndIf Sleep(1);<<<problem here Until $Temp => 12000 Send("{ESC}")You can wrap the entire thing in a While/Wend loop if you want it to repeat... but the code above will not work as expected - so, you might wonder why I would make such a post --- to make this point: lilandywandy said, "...for 12 secs straight..." Now I do not have a full understanding of the Sleep function, but it would seem to me that the color could change and then change back during that one second sleep in Valuater's suggested code and the script may not see it... so, it all boils down to what "straight" means to lilandywandy.Valuater - this post not a slam against your great contributions to this forum by any means. I've just been attempting to follow the knowledge flowing from this discussion of the AutoIt sleep function - http://www.autoitscript.com/forum/index.php?showtopic=13415lilandywandy might not need timing accuracy to the level mentioned in the thread above, but as I pointed out in this post - http://www.autoitscript.com/forum/index.ph...959entry90959 using Sleep(1) can cause large timing errors on the order or 10 to 15 times what you expected to see.As an aside, here is one of Jon's comments on this topic "Sleep/timing/accuracy topic" - http://www.autoitscript.com/forum/index.ph...indpost&p=47734So, lilandywandy, add a zero or two to the "Sleep(1)" line in the code above and take off a zero or two from the "Until $Temp => 12000" line of code until you find a compromise that will work for you.If the color checks must be made as fast as possible, leave the sleep(1) as is and play with the 12000 to get close to 12 seconds. Also, test the code below to see if two single line If statements are faster that one If/Else/Endif. (See the help file about the overhead associated with using EndIf.)$Temp = 0 Do If PixelGetColor(367,708) = Dec(0x00f742) Then $Temp = 0 If NOT PixelGetColor(367,708) = Dec(0x00f742) Then $Temp = $Temp + 1 Sleep(1) Until $Temp => 12000;<<<change as needed Send("{ESC}")You might also test AdLib - I'm not sure if it "watches" for things during "Sleeps" - if it does, then you could use it to reset "temp" to 0.later.... [size="1"][font="Arial"].[u].[/u][/font][/size]
seandisanti Posted July 18, 2005 Posted July 18, 2005 this is the script that i have:$Temp = 0While 1 If PixelGetColor(367,708) <> Dec(0x00f742) Then If $Temp = 0 Then $Timer = TimerInit() EndIf $Temp = 1 If TimerDiff($Timer) > 12000 Then Send("{ESC}") Else $Temp = 0 EndIfWendwhat im trying to do is make a program so that, "when 367,708 has not been 00f742 for 12 secs straight, then press esc". right now, this script seems to just send esc after 12 secs when it is started<{POST_SNAPBACK}>it sounds like the script isn't seeing the color it's looking for... why don't you have your script output the color it's seeing to a tooltip? i use tooltips for debugging alot... i'd just add before the wend... "Tooltip(PixelGetColor(367,708))" that way while it's running, you see what it's seeing in the check...then if necessary you can adjust your condition...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now