Jump to content

Find a specific color.


cxzzD
 Share

Recommended Posts

Hello.

I've been trying to recreate the Windows Info thingy (A very basic clone). I'm currently working on the color of the mouse, but I seem to get into some problems.

Here is the code that I'd like to get to work..

If $Hello = 1 Then

global $mPos = MouseGetPos()

global $mCol = PixelGetColor($mPos[0],$mPos[1])

Sleep(100)

global $result = Hex($mCol,6)

MsgBox(0, "", $result)

;MsgBox(0,"MousePos Color",$mCol&" "&"MousePos x:"& $mPos[0])

$Hello -= 1

EndIf

$ColorFind = PixelSearch(405, 215,947, 570, "0x" & $result) <--- Here is the thing that wont work. I get the error "Variable not declared". What I want it to do is to write out the "$result" variable with an 0x infront of it.

Am I way off or am I somewhat close?

Thanks in advance.

Link to comment
Share on other sites

Hey there!

It's actually what it says, you are trying to use $Hello without declaration :)

Had no probs with your script actually, after having declared the $Hello var you are using:

Global $Hello = 1

If $Hello = 1 Then

global $mPos = MouseGetPos()

global $mCol = PixelGetColor($mPos[0],$mPos[1])

Sleep(100)

global $result = Hex($mCol,6)

MsgBox(0, "", $result)

;MsgBox(0,"MousePos Color",$mCol&" "&"MousePos x:"& $mPos[0])

$Hello -= 1

EndIf

$ColorFind = PixelSearch(405, 215,947, 570, "0x" & $result)

Hope this helps.

Edited by Fender
Link to comment
Share on other sites

Hey there!

Had no probs with your script actually, after having declared the $Hello var you are using:

Global $Hello = 1

If $Hello = 1 Then

global $mPos = MouseGetPos()

global $mCol = PixelGetColor($mPos[0],$mPos[1])

Sleep(100)

global $result = Hex($mCol,6)

MsgBox(0, "", $result)

;MsgBox(0,"MousePos Color",$mCol&" "&"MousePos x:"& $mPos[0])

$Hello -= 1

EndIf

$ColorFind = PixelSearch(405, 215,947, 570, "0x" & "0x" & $result)

Actually that part Is working correctly. But the part that isnt working is the colorfind thing.

Here is the full code, probably should have posted it all from the begining. ;o

HotKeySet("{F6}","_Terminate")

HotKeySet("{F7}","_HejsanPlusOne")

Global $Hello = 0

while 1

If $Hello = 1 Then

global $mPos = MouseGetPos()

global $mCol = PixelGetColor($mPos[0],$mPos[1])

Sleep(100)

global $result = Hex($mCol,6)

MsgBox(0, "", $result)

;MsgBox(0,"MousePos Color",$mCol&" "&"MousePos x:"& $mPos[0])

$Hello -= 1

EndIf

$ColorFind = PixelSearch(405, 215,947, 570, $result)

if IsArray($ColorFind) = True Then

MouseMove($ColorFind[0],$ColorFind[1], 0)

MouseClick("left")

EndIf

WEnd

Func _HejsanPlusOne()

$Hello += 1

EndFunc

Func _Terminate()

Exit 0

EndFunc

Edited by cxzzD
Link to comment
Share on other sites

Mind that you declare a global variable $result in your IF statement, which is kinda dangerous.

In your case, the first time your IF is checked, the $result is not created at all, because the condition is not met ($Hello is NOT 1). Then you get your error, cause the variable is indeed not declared yet.

It's better to declare the $result before you start any checks, and then just use it.

Example:

HotKeySet("{F6}","_Terminate")

HotKeySet("{F7}","_HejsanPlusOne")

Global $Hello = 0

Global $ColorFind = 0

Global $result = 0

while 1

If $Hello = 1 Then

global $mPos = MouseGetPos()

global $mCol = PixelGetColor($mPos[0],$mPos[1])

Sleep(100)

$result = Hex($mCol,6)

MsgBox(0, "", $result)

;MsgBox(0,"MousePos Color",$mCol&" "&"MousePos x:"& $mPos[0])

$Hello -= 1

EndIf

$ColorFind = PixelSearch(405, 215,947, 570, $result)

if IsArray($ColorFind) = True Then

MouseMove($ColorFind[0],$ColorFind[1], 0)

MouseClick("left")

EndIf

WEnd

Func _HejsanPlusOne()

$Hello += 1

EndFunc

Func _Terminate()

Exit 0

EndFunc

Edited by Fender
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...