Jump to content

What is wrong with my code?


Recommended Posts

While 1
    $box = PixelSearch(1530, 500, 1600, 1000, 0xDF3F3F)

    $atakowany = PixelGetColor($box[0], $box[1])
    If $atakowany <> 0xDF3F3F Then
        SoundPlay(@WindowsDir & "\media\tada.wav", 1)
    EndIf
    sleep(1000)
WEnd

 

point is: If a pixel in box change color, play alert

 

What is wrong with my code?

(6) : ==> Subscript used on non-accessible variable.:
$atakowany = PixelGetColor($box[0], $box[1])
$atakowany = PixelGetColor($box^ ERROR
->16:20:27 AutoIt3.exe ended.rc:1

Link to comment
Share on other sites

Try:

While 1
    $box = PixelSearch(1530, 500, 1600, 1000, 0xDF3F3F)
;~  If Not @error Then
;~  If IsArray($box) Then
    If Not @error And IsArray($box) Then
        $atakowany = PixelGetColor($box[0], $box[1])
        If $atakowany <> 0xDF3F3F Then
            SoundPlay(@WindowsDir & "\media\tada.wav", 1)
        EndIf
    EndIf
    Sleep(1000)
WEnd

 

Regards,
 

Link to comment
Share on other sites

This topic makes no sense to me.

Pixelsearch will return with an array ONLY when the pixel at that location is colored 0xDF3F3F. Why do you think that it would suddenly change color so that the PixelGetColor will return anything other than 0xDf3F3F? $atakowany is NEVER going to be <> than that color the way this is being written.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

6 minutes ago, Trong said:

Try:

While 1
    $box = PixelSearch(1530, 500, 1600, 1000, 0xDF3F3F)
;~  If Not @error Then
;~  If IsArray($box) Then
    If Not @error And IsArray($box) Then
        $atakowany = PixelGetColor($box[0], $box[1])
        If $atakowany <> 0xDF3F3F Then
            SoundPlay(@WindowsDir & "\media\tada.wav", 1)
        EndIf
    EndIf
    Sleep(1000)
WEnd

 

no errors but not working  ;/

when i testing = for <> its working ;s

 

5 minutes ago, BrewManNH said:

This topic makes no sense to me.

Pixelsearch will return with an array ONLY when the pixel at that location is colored 0xDF3F3F. Why do you think that it would suddenly change color so that the PixelGetColor will return anything other than 0xDf3F3F? $atakowany is NEVER going to be <> than that color the way this is being written.

like i said:

point is: in box is many pixels in color 0xDF3F3F in random posision . and if in box are total no pixel in color 0xDF3F3F  play alert.

Link to comment
Share on other sites

As I said above, if you're searching in an area for a certain color using PixelSearch, you will always get that color using the array returned by the PixelSearch because that is how the script is written, it will NEVER be anything other than the color you searched for AT THAT LOCATION.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

1 minute ago, BrewManNH said:

As I said above, if you're searching in an area for a certain color using PixelSearch, you will always get that color using the array returned by the PixelSearch because that is how the script is written, it will NEVER be anything other than the color you searched for AT THAT LOCATION.

oh so if color of that pixel will change on my screen , than PixelSearch  will not refresh it in script? ok i understund now,. is any other way to do this?

Link to comment
Share on other sites

23 minutes ago, Trong said:

851579_229801833835099_1670506868_n.png 

While 1
    $box = PixelSearch(1530, 500, 1600, 1000, 0xDF3F3F)
    If IsArray($box) Then SoundPlay(@WindowsDir & "\media\tada.wav", 1)
    Sleep(1000)
WEnd

 

oh this is working but i need reversed version

i used this

While 1
    $box = PixelSearch(1530, 500, 1600, 1000, 0xDF3F3F)
    If IsArray($box) Then
        Sleep(100)
        Else
        SoundPlay(@WindowsDir & "\media\tada.wav", 1)
        EndIf
    Sleep(1000)
WEnd

its works now! can it stay like this? or is there any better way to make reversed @Trong code?

Link to comment
Share on other sites

That should work fine, but you could try to simplify it and take out a few lines. IsArray returns 1 if the check is succesful or a 0 if not. So you could use that bool condition in your If statement instead of the whole function. Not too much different, but it would get rid of the need for an else statement.

$bCheck = IsArray($box)

If $bCheck = 0 Then
    SoundPlay(@WindowsDir & '\media\tada.wav', 1)

 

Link to comment
Share on other sites

Hello, i want to pimp up my script, got something like this:

While 1
$box = PixelSearch(1530, 500, 1600, 1000, 0xDF3F3F)
$bCheck = IsArray($box)

    If $bCheck = 0 Then
        SoundPlay(@WindowsDir & "\media\tada.wav", 1)
    EndIf
    Sleep(1000)
WEnd

While 2
        Send("{CTRLDOWN}{DOWN}{CTRLUP}")
        Sleep(100)
        Send("{CTRLDOWN}{LEFT}{CTRLUP}")
        Sleep(180000)
WEnd

First part: scan box all the time and do something

Second part: do something every 3 min

But i think i cant use it in this way, becouse second loop is not working.

I need to get first loop working like right now + independently do something every for example 3 min.

Edited by LuisPro
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...