Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

I have a question about Index.


  • Please log in to reply
10 replies to this topic
HOHOHI
  • Guests
  • Last active:
  • Joined: --
CheckNumber:
Loop, 10
{
ImageSearch, OutX, OutY, %A1%, %A2%, %A3%, %A4%, %Index%.bmp
If not errorlevel
{
;You have found the image. The number is in the variable Index
Number := Index
}
}
Msgbox, You found the number, its "%Number%"
Number = ;;
}

i would like to use the name of images as a number.
i only can see found the number, its ""
there is nothing in ""
could you help me what is wrong?

janopn
  • Members
  • 694 posts
  • Last active: Jun 12 2017 03:41 PM
  • Joined: 08 Jul 2011

CheckNumber:
Loop, 10
{
ImageSearch, OutX, OutY, %A1%, %A2%, %A3%, %A4%, %Index%.bmp
If not errorlevel
{
;You have found the image. The number is in the variable Index
Number := Index
}
}
Msgbox, You found the number, its "%Number%"
Number = ;;
}

i would like to use the name of images as a number.
i only can see found the number, its ""
there is nothing in ""
could you help me what is wrong?


Hi!

System variable is A_Index, not Index.
CheckNumber: 
Loop, 10 
{ 
ImageSearch, OutX, OutY, %A1%, %A2%, %A3%, %A4%, %Index%.bmp 
If not errorlevel 
{ 
;You have found the image. The number is in the variable Index 
Number := A_Index ;there
} 
} 
Msgbox, You found the number, its "%Number%" 
Number = ;;
}

Oh, and use CODE tags, please! :)
All in all is all we are ~

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
<!-- m -->http://www.autohotke...mmands/Loop.htm<!-- m -->

The built-in variable A_Index contains the number of the current loop iteration.

The name of the variable is "a_index" not "index" , please read the documentation more carefully.


In the future, please post your script within [code] [/code] tags
There is a button [code=auto:0] just above the window where you type your message.

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
@ janopn

You missed changing one of the variables in the script.

HOHOHI
  • Guests
  • Last active:
  • Joined: --

@ janopn

You missed changing one of the variables in the script.

CheckNumber: 
Loop, 10 
{ 
Index := A_Index-1
ImageSearch, OutX, OutY, %A1%, %A2%, %A3%, %A4%, %Index%.bmp 
If not errorlevel 
{ 
;
Number := A_Index-1
} 
} 
Msgbox, You found the number, its "%Number%" 
Number = ;;
}

thanks for replying it helped a lot.

The name and number of image start from 0-9 so i put A_index-1.

i want to find the number with image search.

i still dont know why it just show




im new in AHK so its hard to find the problem to me =(

could you help me?

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
Hi HOHOHI, welcome to the forum. Thank you for posting with code tags.

Another thing that is most useful is posting a complete script.
The following shows that you didn't post a complete script.
Error: Missing "{"

	013: MsgBox,You found the number, its "%Number%"
	014: Number = 
--->	015: }
	020: Loop,10
	021: {

If I remove the extra } there are values missing for the variables A1...A4
ImageSearch, OutX, OutY, %A1%, %A2%, %A3%, %A4%, %Index%.bmp

If they are truely missing, then the imagesearch will not find anything,
You might even get errorlevel =2 :shock:

if there was a problem that prevented the command from conducting the search (such as failure to open the image file or a badly formatted option).


The reason you saw <You found the number, its "" > is because nothing was found.

HOHOHI
  • Guests
  • Last active:
  • Joined: --
{
A1 := 248
A2 := 58 
A3 := 251  
A4 := 63

CheckNumber: 
Loop, 10 
{ 
Index := A_Index-1
ImageSearch, OutX, OutY, %A1%, %A2%, %A3%, %A4%, %Index%.bmp 
If not errorlevel 
{ 
;You have found the image. The number is in the variable Index 
Number := A_Index-1
} 
} 
Msgbox, You found the number, its "%Number%" 
Number = ;;
}

even i opend the image file and put on the exact picture adress..
hmm... i still looking for problem now.. could you see what is wrong?

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
Well I looked at the 4 variables in your new posting and they appear inside the loop.
It seem that you have a rather small search area 4 x 6 pixels
Is that what you want?
How big is the actual image ?


I'm going to make the assumption that you are working with a game.

Are you certain that AHk can "see" the game ?

try these steps, exactly.

1. open the game (windowed mode) as you stated.
2. hit printscreen button
3. close game complete (very important)
4. open M.S. Paint
5. hit control-v to paste the clipboard to paint.
6. can you see the image of the game as it was when you hit printscreen ?

7. if you can see it, good; if not, neither can AHk

If AHk can see the image, here is a modified version of your script.
{
A1 := 248
A2 := 58
A3 := 251 
A4 := 63


result= index errorlevel`r`n

CheckNumber:
Loop, 10
{
  Index := A_Index-1
  ImageSearch, OutX, OutY, %A1%, %A2%, %A3%, %A4%, %Index%.bmp
  result.= index a_tab errorlevel "`r`n"
  If not errorlevel
  {
    ;You have found the image. The number is in the variable Index
    Number := A_Index-1
  }
}
Msgbox, You found the number, its "%Number%"
msgbox full results`r`n%result%
Number = ;;
}
When the "full results" msgbox is open you can hit ^c to copy the contents and paste them into a reply.
Please use code tags to preserve the formatting.

---------------------------
test.ahk
---------------------------
full results

index errorlevel

0	2

1	1

2	1

3	2

4	2

5	2

6	2

7	2

8	2

9	2


---------------------------
OK   
---------------------------


HOHOHI
  • Guests
  • Last active:
  • Joined: --

Well I looked at the 4 variables in your new posting and they appear inside the loop.
It seem that you have a rather small search area 4 x 6 pixels
Is that what you want?
How big is the actual image ?


I'm going to make the assumption that you are working with a game.

Are you certain that AHk can "see" the game ?

try these steps, exactly.

1. open the game (windowed mode) as you stated.
2. hit printscreen button
3. close game complete (very important)
4. open M.S. Paint
5. hit control-v to paste the clipboard to paint.
6. can you see the image of the game as it was when you hit printscreen ?

7. if you can see it, good; if not, neither can AHk

If AHk can see the image, here is a modified version of your script.

{
A1 := 248
A2 := 58
A3 := 251 
A4 := 63


result= index errorlevel`r`n

CheckNumber:
Loop, 10
{
  Index := A_Index-1
  ImageSearch, OutX, OutY, %A1%, %A2%, %A3%, %A4%, %Index%.bmp
  result.= index a_tab errorlevel "`r`n"
  If not errorlevel
  {
    ;You have found the image. The number is in the variable Index
    Number := A_Index-1
  }
}
Msgbox, You found the number, its "%Number%"
msgbox full results`r`n%result%
Number = ;;
}
When the "full results" msgbox is open you can hit ^c to copy the contents and paste them into a reply.
Please use code tags to preserve the formatting.

---------------------------
test.ahk
---------------------------
full results

index errorlevel

0	2

1	1

2	1

3	2

4	2

5	2

6	2

7	2

8	2

9	2


---------------------------
OK   
---------------------------


---------------------------
test.ahk
---------------------------
full results

index errorlevel

0	2

1	2

2	2

3	2

4	2

5	2

6	2

7	2

8	2

9	2


---------------------------
OK   
---------------------------

oh and i only have number 0 image file now,im gonna add 1-9 after i could reconize 0. its 4x6bmp image file.

thankg you agian.

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
You say that you only have 1 image # 0 ?
Then why bother with 1..10 ?

Notice that for ALL the images, the errorleve is 2 which means:

there was a problem that prevented the command from conducting the search (such as failure to open the image file or a badly formatted option).



HOHOHI
  • Guests
  • Last active:
  • Joined: --

You say that you only have 1 image # 0 ?
Then why bother with 1..10 ?

Notice that for ALL the images, the errorleve is 2 which means:

there was a problem that prevented the command from conducting the search (such as failure to open the image file or a badly formatted option).


My mistake.. put wrong adress where the image file located..
It works now. thank you!=)