Sign in to follow this  
Followers 0
erkkipetteri

Simple PixelSearch script crashing...

6 posts in this topic

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);

}

}

}

Share this post


Link to post
Share on other sites



I don't get a crash at first script...Post a debug !

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 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]

Share this post


Link to post
Share on other sites

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"

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by erkkipetteri

Share this post


Link to post
Share on other sites

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.

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