Is there something missing from my script?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Interknet
Posts: 2
Joined: 20 Sep 2015, 16:58

Is there something missing from my script?

20 Sep 2015, 17:06

What I want this code to do:
I want it to loop the button A if pixel change is detected on the right side, and I want the D button to be looped when pixel change is detected on the left side.

Problems:
Currently it doesn't seem to switch between the two checks, and all I see is A D A D A D.

What I noticed is that loop within a loop seems to not work quite so well.

Offsets are set correctly and such - it's just that when Check2 is "True", then A should stop being looped, and then switch to pressing D.

Full code:

Code: Select all


AutoPlay = 0
AutoPlay1 = 0
AutoPlay2 = 0


Check1 := if (((R1-Sensitivity)<=R2) && ((R1+Sensitivity)<=R2)) or (((R1-Sensitivity)>=R2) && ((R1+Sensitivity)>=R2)) or (((G1-Sensitivity)<=G2) && ((G1+Sensitivity)<=G2)) or (((G1-Sensitivity)>=G2) && ((G1+Sensitivity)>=G2)) or (((B1-Sensitivity)<=B2) && ((B1+Sensitivity)<=B2)) or (((B1-Sensitivity)>=B2) && ((B1+Sensitivity)>=B2))
Check2 := if (((R3-Sensitivity)<=R4) && ((R3+Sensitivity)<=R4)) or (((R3-Sensitivity)>=R4) && ((R3+Sensitivity)>=R4)) or (((G3-Sensitivity)<=G4) && ((G3+Sensitivity)<=G4)) or (((G3-Sensitivity)>=G4) && ((G3+Sensitivity)>=G4)) or (((B3-Sensitivity)<=B4) && ((B3+Sensitivity)<=B4)) or (((B3-Sensitivity)>=B4) && ((B3+Sensitivity)>=B4))


#MaxThreadsPerHotkey 2

;AutoPlay Stuff
OffsetX:=200
OffsetY:=0
Sensitivity:=5
SplitRGBColor(RGBColour, ByRef Red, ByRef Green, ByRef Blue)
{
    Red := RGBColour >> 16 & 0xFF
    Green := RGBColour >> 8 & 0xFF
    Blue := RGBColour & 0xFF
}



F13::
AutoPlay := !AutoPlay
SoundPlay, %A_ScriptDir%\Autoplay.mp3
Hotkey, *~$Space
return
 
*~$Space::
While AutoPlay{
 loop {
  GetKeyState, SpaceState, Space, P  
  if Spacestate = U
  break  
  MouseGetPos, Pos1X, Pos1Y
  PixelGetColor, ColourOne, Pos1X+OffsetX, Pos1Y+OffsetY
  SplitRGBColor(ColourOne, R1, G1, B1)
  MouseGetPos, Pos2X, Pos2Y
  PixelGetColor, ColourTwo, Pos2X+OffsetX, Pos2Y+OffsetY
  SplitRGBColor(ColourTwo, R2, G2, B2)
  MouseGetPos, Pos3X, Pos3Y
  PixelGetColor, ColourThree, Pos3X-OffsetX, Pos3Y+OffsetY
  SplitRGBColor(ColourThree, R3, G3, B3)
  MouseGetPos, Pos4X, Pos4Y
  PixelGetColor, ColourFour, Pos4X-OffsetX, Pos4Y+OffsetY
  SplitRGBColor(ColourFour, R4, G4, B4)
  if Check1
    loop {
     Send, a
     if Check2
     break
    }
  if Check2
   loop {
    Send, d
     if Check1
     break
    } 
  }
}
return

 
;------------------------------------Exit Script
F18::
SoundPlay, %A_ScriptDir%\ClosingScript.mp3, wait
ExitApp
return
Thanks in advanced. Hope someone can help with this one.
User avatar
sinkfaze
Posts: 616
Joined: 01 Oct 2013, 08:01

Re: Is there something missing from my script?

21 Sep 2015, 08:59

Is this your actual code or did you modify it before you posted it? I ask because, unless I've been out of the loop for far too long, you don't have valid code feeding the Check1 and Check2 variables. You'll likely want to use a ternary statement to assign values to those variables:

Code: Select all

Check1 :=	(((R1-Sensitivity)<=R2)+((R1+Sensitivity)<=R2)=2) ; if 2 then both statements are true
		 || (((R1-Sensitivity)>=R2)+((R1+Sensitivity)>=R2)=2)
		 || (((G1-Sensitivity)<=G2)+((G1+Sensitivity)<=G2)=2)
		 || (((G1-Sensitivity)>=G2)+((G1+Sensitivity)>=G2)=2)
		 || (((B1-Sensitivity)<=B2)+((B1+Sensitivity)<=B2)=2)
		 || (((B1-Sensitivity)>=B2)+((B1+Sensitivity)>=B2)=2) ? 1 : 0

Check2 :=	(((R3-Sensitivity)<=R4)+((R3+Sensitivity)<=R4)=2)
		 || (((R3-Sensitivity)>=R4)+((R3+Sensitivity)>=R4)=2)
		 || (((G3-Sensitivity)<=G4)+((G3+Sensitivity)<=G4)=2)
		 || (((G3-Sensitivity)>=G4)+((G3+Sensitivity)>=G4)=2)
		 || (((B3-Sensitivity)<=B4)+((B3+Sensitivity)<=B4)=2)
		 || (((B3-Sensitivity)>=B4)+((B3+Sensitivity)>=B4)=2) ? 1 : 0
Interknet
Posts: 2
Joined: 20 Sep 2015, 16:58

Re: Is there something missing from my script?

21 Sep 2015, 16:45

Yeah I moved them cause I thought it would look cleaner. But they do work the same way they do when they aren't put as Check1 and Check2.

Don't pay attention to that part of code, I'm sure it works correctly xD
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Is there something missing from my script?

21 Sep 2015, 17:03

Interknet wrote:Yeah I moved them cause I thought it would look cleaner. But they do work the same way they do when they aren't put as Check1 and Check2.

Don't pay attention to that part of code, I'm sure it works correctly xD
first, don't move stuff, because you've done it wrong. that code does not work.

check1 and check2 are only set and checked during the auto execute section of the script. that means those variables will be set once, and never checked again. further, during the autoexec section, the R1,R2,R3 variables that are part of the condition are blank, so of course they will never be used.

so during your space hotkey while loop, it is just using the original values that were checked when the script started. if you want to detect a pixel change, then you probably want it to keep checking those long if conditions, so you need to check them again at the moment you want to need the values


Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 94 guests