erkkipetteri Posted April 24, 2008 Posted April 24, 2008 My script simply crashes. I've tried searching things about PixelSearch but i can't find anything. Here's the script: HotKeySet ("{SPACE}", "Sihtaus") Func Sihtaus() While 1 $pelaaja = PixelSearch (69,69,729,439, 0x000000) if PixelGetColor ($pelaaja[0] + 1, $pelaaja[1]) = 0x000000 Then if PixelGetColor ($pelaaja[0], $pelaaja[1] + 1) = 0x000000 Then MouseMove ($pelaaja[0], $pelaaja[1], 0) EndIf EndIf WEnd EndFunc ...And i also have a GetDIBits C++ problem, this also simply crashes: CODE#include <cstdlib> #include <iostream> #include <windows.h> using namespace std; int main(){ while (1) { if (GetAsyncKeyState(VK_DOWN) & 0x8000) { break; BITMAPINFO minfo; minfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); minfo.bmiHeader.biWidth = 660; minfo.bmiHeader.biHeight = -370; minfo.bmiHeader.biPlanes = 1; minfo.bmiHeader.biBitCount = 32; minfo.bmiHeader.biCompression = BI_RGB; minfo.bmiHeader.biSizeImage = ((((660 * 32) + 31) / 32) * 4) * 370; HDC ruutuDc = GetDC(0); HDC kigeDc = CreateCompatibleDC(ruutuDc); HBITMAP kigekuva = CreateCompatibleBitmap(ruutuDc, 660, 370); SelectObject (kigeDc, kigekuva); BitBlt (kigeDc, 0, 0, 660, 370, ruutuDc, 69, 69, SRCCOPY); long Pikselit[660][370]; GetDIBits (kigeDc, kigekuva, 0, 370, Pikselit, &minfo, DIB_RGB_COLORS); } } }
mafioso Posted April 24, 2008 Posted April 24, 2008 I don't get a crash at first script...Post a debug !
Ealric Posted April 24, 2008 Posted April 24, 2008 (edited) Run this so you can visually see what your script is doing. For one thing if black isn't found it's stuck in the loop so you might want to add an ESC hotkey to break out of the loop. HotKeySet ("{SPACE}", "Sihtaus") HotKeySet ("{ESC}", "_exitloop") While 1 sleep(0030) WEnd Func Sihtaus() MsgBox(0,"","Entered Sihtaus",1) While 1 $pelaaja = PixelSearch (69,69,729,439, 0x000000) if PixelGetColor ($pelaaja[0] + 1, $pelaaja[1]) = 0x000000 Then if PixelGetColor ($pelaaja[0], $pelaaja[1] + 1) = 0x000000 Then MouseMove ($pelaaja[0], $pelaaja[1], 0) Else MsgBox(0,"",$pelaaja[0] & "," & $pelaaja[1]+1 & " not black",1) EndIf Else MsgBox(0,"",$pelaaja[0]+1 & "," & $pelaaja[1] & " not black",1) EndIf WEnd EndFunc Func _exitloop() exit 0 EndFunc Edited April 24, 2008 by Ealric My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]
Siao Posted April 24, 2008 Posted April 24, 2008 Guess what happens when you try to access an array that doesn't exist. You obviously searched "things about PixelSearch" in the wrong places. Where you should look at is its reference in the helpfile, particularly return values. "be smart, drink your wine"
erkkipetteri Posted April 24, 2008 Author Posted April 24, 2008 (edited) Thanks Ealric, for some reason the sleep-loop made my script stable. Now it works perfectly! EDIT: Oops, i didn't know that it needs a "body" to run correctly... Edited April 24, 2008 by erkkipetteri
Moderators SmOke_N Posted April 24, 2008 Moderators Posted April 24, 2008 Thanks Ealric, for some reason the sleep-loop made my script stable. Now it works perfectly! EDIT: Oops, i didn't know that it needs a "body" to run correctly...What Siao is saying.... You assume that PixelSearch will always succeed with your If PixelGetColor() = 0x000000 statement. He is suggesting something like: If IsArray($pelaaja) AND PixelGetColor ($pelaaja[0] + 1, $pelaaja[1]) = 0x000000 Then Or If Not @error AND PixelGetColor ($pelaaja[0] + 1, $pelaaja[1]) = 0x000000 Then Note the checking to make sure PixelSearch did not fail before continuing on to manipulate our other functions with an assumed array. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
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