PixelGetColor Or PixelSearch for a game Topic is solved

Ask gaming related questions
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 12:44

Replace the Send with MsgBox until you have the script working.

Does it work at that point, showing the MsgBox?

Remember that your search occurs only once, so when you press "g", the color would need to exist in the coordinate range that you specified. Is that the case?

Your current script directs the Send command to occur if the color is not found.

All you really need to debug is the following and nothing else.

Code: Select all

g::
PixelSearch, Px, Py, 790, 885, 1080, 920, 0x49423A, 3, Fast
MsgBox, 64, ErrorLevel, %ErrorLevel%
Return
When ready, run the script, activate your window, and then press g. You can then see what the ErrorLevel is.

This uses coordinates relative to the active window. If you want absolute coordinates, put CoordMode, Pixel at the top.
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 13:12

Yeah, now the MsgBox it's ok.

https i.imgur.com /Tmu0dYG.png Broken Link for safety
Last edited by Giani123 on 04 Jan 2021, 17:07, edited 2 times in total.
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 13:42

OK, so you are making progress. Now, with the MsgBox working-- and an ErrorLevel of 0-- then it means that you can simply substitute the Send command, or do something like the following.

Code: Select all

g::
PixelSearch, Px, Py, 790, 885, 1080, 920, 0x49423A, 3, Fast
If !ErrorLevel {
 Send e
 SoundBeep, 1500, 30
} Else MsgBox, 48, Error, Pixel was not found.
Return
Remember that Send sends to the active window.
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game  Topic is solved

04 Jan 2021, 14:49

Code: Select all

x1 := 790, y1 := 885, x2 := 1080, y2 := 920, targetColor := 0x49423A, timerFreq := 25

g::
If (go := !go) {
 SetTimer, Check, %timerFreq%
 ToolTip, %A_Space%`n   Searching   `n%A_Space%, 50, 50
 SoundBeep, 1400, 30
 Return
}
Reset:
SetTimer, Check, Off
ToolTip
go := False
SoundBeep, 1000, 30
Return

Check:
PixelSearch,,, %x1%, %y1%, %x2%, %y2%, %targetColor%, 3, Fast
If ErrorLevel
 Return
Gosub, Reset
MsgBox, 64, Success, Found it! ; After working, replace with: Send e
Return
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 16:48

Wow, first time when it's working ! Thanks so much for all your help :D
And i have a question, can i reduce the E key "lag". sometimes the blue line comes faster and passes the grey dot.
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 19:37

Things that might help (no guarantee):

1. SetBatchLines
2. Decrease timerFreq
3. Shrink the area to search
4. Use SendInput instead of Send
5. Decrease variation parameter in the pixel search
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 19:47

Thanks for answer. I changed the timerFreq and it seems to be going better (Remains to be seen).
Just last thing to add at this if it's possible. If the script also hit the grey area or not, send and "Enter" key then make a loop and repeat this procces.
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 19:55

I leave this to you. You can insert Send {Enter} wherever needed in the timer routine.
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 20:02

Code: Select all

x1 := 790, y1 := 885, x2 := 1080, y2 := 920, targetColor := 0x49423A, timerFreq := 25

g::
loop
      {

If (go := !go) {
 SetTimer, Check, %timerFreq%
 ToolTip, %A_Space%`n   Searching   `n%A_Space%, 50, 50
 SoundBeep, 1400, 30
 Return
}
Reset:
SetTimer, Check, Off
ToolTip
go := False
SoundBeep, 1000, 30
Return

Check:
PixelSearch,,, %x1%, %y1%, %x2%, %y2%, %targetColor%, 3, Fast
If ErrorLevel
 Return
Gosub, Reset
MsgBox, 64, Success, Found it! ; After working, replace with: Send e
Return
Send {Enter}
}
For example like this ? :)
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 20:37

Yes, you can do that, but put it before Return, and remove the final closing brace.
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

05 Jan 2021, 10:40

I tried different ways but the script press the Enter key once only if the color search was succed, and after the script it doesn't work anymore. (need to press G key again, not a loop)
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game

05 Jan 2021, 11:12

Feel free to post your revision.
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

05 Jan 2021, 12:18

Code: Select all

g::
loop
{
If (go := !go) {
 SetTimer, Check, %timerFreq%
 ToolTip, %A_Space%`n   Searching   `n%A_Space%, 50, 50
 SoundBeep, 1400, 30
 Return
}

Reset:
SetTimer, Check, Off
ToolTip
go := False
SoundBeep, 1000, 30
Return

Check:
PixelSearch,,, %x1%, %y1%, %x2%, %y2%, %targetColor%, 3, Fast
If ErrorLevel
 Return
Gosub, Reset
Send E
Send {Enter}
Sleep 2000
Return
}
Return
I think i need one more condition. For example, if color was detected/not detected, "Sleep 1-2seconds", press Enter and reload script.
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game

05 Jan 2021, 14:21

You could try the following version. This is not a great flow, but the script works overall. Someone may be able to improve it.

Code: Select all

SetBatchLines -1
x1 := 790, y1 := 885, x2 := 1080, y2 := 920, targetColor := 0x49423A, timerFreq := 20

g::Gosub, % (go := !go) ? "Start" : "Stop"

Start:
SoundBeep, 1400, 30
ToolTip, %A_Space%`n   Searching   `n%A_Space%, 50, 50
Sleep, 50
SendInput {Enter}
SetTimer, Check, %timerFreq%
Check:
PixelSearch,,, %x1%, %y1%, %x2%, %y2%, %targetColor%, 2, Fast
If !ErrorLevel && go {
 SendInput e
 Gosub, Stop
 Sleep, 1500
 If go
  Gosub, Start
}
Return

Stop:
SetTimer, Check, Off
SoundBeep, 1000, 30
ToolTip
Return
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

05 Jan 2021, 19:42

Thanks! I can say that it works 95%. I think it's about timing to "Sleep, 1500". I will try to play with this value and will come back with an update later!
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game

05 Jan 2021, 19:46

OK. The 1500 is just a pause before the next Enter, so you could decrease that to anything, such as 500 or 200, for example.
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

05 Jan 2021, 20:01

mikeyww wrote:
05 Jan 2021, 19:46
OK. The 1500 is just a pause before the next Enter, so you could decrease that to anything, such as 500 or 200, for example.
I will try next days to do it better but I had a better idea, i did a script that press {Enter} every 3 seconds, lol :bravo:
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game

05 Jan 2021, 20:07

OK. That's what I meant by a second timer. Sounds like you have it!
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

06 Jan 2021, 13:48

I have a question if i want to add another color near how do i proceed?

Code: Select all

targetColor := 0x49423A, 0x49423A
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game

06 Jan 2021, 14:21

Code: Select all

Check:
PixelSearch, x,, %x1%, %y1%, %x2%, %y2%, %targetColor1%, 2, Fast
If (x = "")
 PixelSearch, x,, %x1%, %y1%, %x2%, %y2%, %targetColor2%, 2, Fast
If (x != "" && go) {
 SendInput e
 Gosub, Stop
 Sleep, 1500
 If go
  Gosub, Start
}
Return

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 14 guests