Rhythm game tapping help

Ask gaming related questions (AHK v1.1 and older)
BecauseICan
Posts: 3
Joined: 11 Jul 2016, 23:25

Rhythm game tapping help

11 Jul 2016, 23:34

I'm trying to make a script for a rhythm game. There are note placements on the screen, and when the note changes color, you tap that location.

Here's what I have so far:

Code: Select all

PixelGetColor, NoteColor, 960, 1050 ; NoteColor is the color of the note

Loop
{
	PixelGetColor, NoteColorTap, 960, 1050 ; NoteColorTap is the color of the note when you're supposed to tap it
	if %NoteColorTap% != %NoteColor% ; If colors don't match
	SendInput, {space} ; Tap the note using the space bar 
}

It's supposed to continuously check the Pixel Color of the note, and when it changes you tap it once. But my code above simply taps continuously with no regard to the changing colors. Any help is appreciated.
grant
Posts: 323
Joined: 14 Oct 2015, 17:27

Re: Rhythm game tapping help

12 Jul 2016, 04:56

Code: Select all

f1::													;trigger to start the program, change to what works for you
loop
	{

	PixelGetColor, NoteColor, 960, 1050 								; NoteColor is the color of the note
	
		Loop
			{
			PixelGetColor, NoteColorTap, 960, 1050 						; NoteColorTap is the color of the note when you're supposed to tap it
			if (%NoteColorTap% != %NoteColor%)							; If colors don't match
				{
				SendInput, {space} 										; Tap the note using the space bar 
				sleep, 50								;fiddle with this, you need to give the program a chance to refresh the screen before getting the colors again
				break									;you need to get out of this loop to get the new note from the first loop
				}
			}
 
	}
	
	
	
esc::escape												;good to have an exit in case of a bug
BecauseICan
Posts: 3
Joined: 11 Jul 2016, 23:25

Re: Rhythm game tapping help

13 Jul 2016, 23:00

Hi grant, thanks for the help. I managed to make it work with one note at a time.

However, my problem now is that there are multiple note placements on the screen. With the current code, it only works on the middle note.

How would I go about making this work for 3 notes on the screen? My attempt so far uses SetTimer to run 3 Loops. Unfortunately, when I activate more than one timer, the script doesn't work anymore.

Code: Select all

SetTimer, Loop1, 100
SetTimer, Loop2, 100
SetTimer, Loop3, 100
return

Loop1:
Loop {
	PixelGetColor, NoteColor1, 210, 300
 
		Loop
			{
			PixelGetColor, NoteColorTap1, 210, 300 						
			if (NoteColorTap1 != NoteColor1)							
				{
					send, {1} 										
					sleep, 50					          				
					break										        
				}
			}     
	}

Loop2:
Loop {
	PixelGetColor, NoteColor2, 260, 580
 
		Loop
			{
			PixelGetColor, NoteColorTap2, 260, 580 						
			if (NoteColorTap2 != NoteColor2)							
				{
					send, {2} 										
					sleep, 50					          							
					break										          			
				}
			}   
	}

Loop3:
Loop {
	PixelGetColor, NoteColor3, 420, 820
 
		Loop
			{
			PixelGetColor, NoteColorTap3, 420, 820 						
			if (NoteColorTap3 != NoteColor3)							
				{
					send, {3} 										
					sleep, 50					          							
					break										  
				}
			}
	}
grant
Posts: 323
Joined: 14 Oct 2015, 17:27

Re: Rhythm game tapping help

14 Jul 2016, 02:23

Multiple timers start tripping over each other and you may need to use other methods.
Spoiler
I would start with multiple toolboxes to display on screen the notes (colors). Do this for all the various note locations you use above and all at the same time so you can see how they interact. Then you can start to think about how you can use the colors and how they change to trigger the various sends that you have.

Code: Select all

f1::

loop
{

PixelGetColor, note1, 200, 200
PixelGetColor, note2, 300, 200
PixelGetColor, note3, 400, 200
PixelGetColor, note4, 500, 200

ToolTip, % note1, 200, 150, 1
ToolTip, % note2, 300, 150, 2
ToolTip, % note3, 400, 150, 3
ToolTip, % note4, 500, 150, 4

}
return
esc::exitapp

If you see that the active note is the only fixed pixel, then you can use that as a trigger.
If they are all stationary, then you will have to monitor all of them to determine which one changes.
If the new note is displayed instantaneously, you will have 2 changes, so you will then need to keep track of the previous note as well so that you know which one of the 2 to monitor.
If they are all, always changing, you have a different challenge and perhaps your note is changing less than the others and you can use that.

I do not think that this is not a *difficult* problem, but it is a nice challenge. There are potentially many variables that can influence how you need to approach this.
BecauseICan
Posts: 3
Joined: 11 Jul 2016, 23:25

Re: Rhythm game tapping help

14 Jul 2016, 05:00

Thanks for telling me about ToolTip!
grant wrote:If they are all stationary, then you will have to monitor all of them to determine which one changes.
This seems most relevant to my game. So far I've set 9 ToolTips to monitor each note position. As you can see from the image, the notes that I have to tap are the red circles that start at the top center and move towards the note positions. PixelGetColor keeps track of a pixel on the border of the note position. When the red circle overlaps, then PixelGetColor should be different than usual. If that's the case, then I send an Input to tap that note.

Image

But my problem now becomes how to monitor 9 individual note positions. You've taught me that SetTimer can't mirror threading, so I wonder if there's an alterative in AHK.
grant
Posts: 323
Joined: 14 Oct 2015, 17:27

Re: Rhythm game tapping help

14 Jul 2016, 05:52

That is not what I meant for you to use the tooltip for. Use the tooltip to visually see if and when the color changes, games often have a bit of color change to keep your attention or distract and these are sometimes minor enough that you can not see them but they will effect your program.

Stationary???? - What drivel was I typing??? - I meant fixed, i.e. the color does not change at all.
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Rhythm game tapping help

14 Jul 2016, 07:33

how do you play this game on pc??
:wave: There is always more than one way to solve a problem. ;)

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: ReyAHK and 91 guests