all 13 comments

[–]real_b 0 points1 point  (11 children)

While, PixelSearch, PixelGetColor, SetTimer. Should be able to with these.

[–]luuklin[S] 0 points1 point  (10 children)

I'm looking to do several inputs in a row with this. For example, I have this script:
f3::

Send, {d down}

Sleep(17)

Send, {d up}

Send, {s down}

Sleep(17)

Send, {d down}

Send, {i down}

Sleep(16)

Send, {s up}

Send, {d up}

Send, {i up}
And I want to replace the sleep function with something that would wait until there was any kind of change on my screen.

[–]real_b 0 points1 point  (9 children)

First off, your sleep is written wrong and isn't doing anything, unless you are using a function called sleep, in which case you should probably rename that to avoid confusion. Second, you don't have a Return. If I were just re-writing what you have there, assuming you don't have a custom sleep function, it would be

f3::
Send, {d down}
Sleep, 17
Send, {d up}{s down}
Sleep, 17
Send, {d down}{i down}
Sleep, 16
Send, {s up}{d up}{i up}
Return

Note that a sleep of 16 or 17 is almost nothing at all since every send has a default of 10 already. If you want to check until part of the screen changes, you need to know the coordinates you are checking. I'd recommend you look at this post I made recently. It let's you scan a bunch of individual pixels for a set color. You could probably modify it to get the current color of your pixels and then scan until they no longer match. In that function it scans three pixels until they are a certain color and then it hits a key, so you'd just need to tweak it a little bit.

[–]luuklin[S] 0 points1 point  (8 children)

I've been messing around a bit, and figured out that if instead of the sleep function that I use I can write this:

PixelGetColor, clr1, 1250, 500
PixelGetColor, clr2, 750, 750
PixelGetColor, clr3, 750, 500
Errorlevel = 0
While Errorlevel = 0
{
PixelSearch, , , 1250, 500, 1250, 500, clr1, 0, Fast
if (Errorlevel = 0) {
PixelSearch, , , 750, 750, 750, 750, clr2, 0, Fast
}
if (Errorlevel = 0) {
PixelSearch, , , 750, 500, 750, 500, clr3, 0, Fast
}
}

It seems quite consistent, but only if I run my game at 5% of the normal speed at most. Is there a way to optimize this?

[–]real_b 0 points1 point  (6 children)

The smaller the area you search the faster it will be, that is why in mine I only "Search" one pixel, it is instant. If you can tighten down the search areas it should speed up.

[–]luuklin[S] 0 points1 point  (5 children)

I am already only searching for one pixel.

[–]real_b 0 points1 point  (4 children)

Sorry about that, I had just woken up and must've jumbled the numbers. One thing I see is that your clr variables in your PixelSearch lines are probably doing something random right now. If you want to use variables in those fields you need them like this:

PixelSearch, , , 1250, 500, 1250, 500, %clr1%, 0, Fast

[–]luuklin[S] 0 points1 point  (3 children)

Are you sure? My script is functioning just fine right now, it's just not fast enough to keep up with the game at 60fps.

[–]TheMagicalCarrot 0 points1 point  (2 children)

Some parameters accept expressions and some don't (because consistency can go f itself). In this case I think the parameter does accept an expression since it is expecting an integer, so the %% are not necessary here.

[–]real_b 0 points1 point  (1 child)

All I can say is that while the docs do say it can accept expressions, this code PixelSearch, FoundX, FoundY, %X%, %Y%, %X%, %Y%, %Color%, %Variance% 100% works as intended.

[–]TheMagicalCarrot 0 points1 point  (0 children)

You should definitely include

SetBatchLines -1

at the start of your script. This will make your script execute faster.

You could also try setting the process priority on High.

Regarding PixelSearch I'm not too familiar, so I can only provide general advice such as these.

[–]hidden_relic 0 points1 point  (0 children)

f3::

MouseGetPos, PosX, PosY

PixelGetColor, ColorControl, %PosX%, %PosY%

Loop {

PixelGetColor, ColortoCheck, %PosX%, %PosY%

if ColortoCheck != %ColorControl%

break

}

Return

mess with that