karudish

For..To loops and ImageSearch

6 posts in this topic

#1 ·  Posted (edited)

I'm having a problem building a for.. to loop with a imagesearch inside

My code:

#include <ImageSearch.au3>
#RequireAdmin

Global $xfindsteps = 0
Global $yfindsteps = 0
$xdef = 0
$ydef = 0
Sleep(2000)

If _ImageSearchArea("C:\Users\Ricardo\Desktop\RealFont\Steps.png", 0, 270, 223, 307, 232, $xfindsteps, $yfindsteps, 0) = 1 Then
   MsgBox(0,"","Encontrou")
Else
   MsgBox(0,"","Nada")
EndIf

$novo_x = $xfindsteps - 8
$novo_x2 = $xfindsteps - 14

;;HERE BELOW, I GOT THE PROBLEM

For $i = 9 To 0
If _ImageSearchArea("C:\Users\Ricardo\Desktop\RealFont\" & $i & ".png", 0, $novo_x2, 223, $novo_x, 232, $xdef, $ydef, 0) = 1 Then $res = $i
Next

MsgBox(0,"",$res)

So, when i use this code, the last MsgBox() doesn't even appear. The script simply exits after the first MsgBox.

But if instead of a "For" loop i do this:

If _ImageSearchArea("C:\Users\Ricardo\Desktop\VIRTUADOPT\RealFont\5.png", 0, $novo_x2, 223, $novo_x, 232, $xdef, $ydef, 0) = 1 Then $res = 5

MsgBox(0,"",$res)

The MsgBox works and retrives the "5" that i'm expecting..

What did i wrong?

Edited by karudish

Share this post


Link to post
Share on other sites



For $i = 9 To 0 Step - 1

Share this post


Link to post
Share on other sites

Thanks for your answer but I've already tried that.. Also, step - 1 should be default

 

Share this post


Link to post
Share on other sites

By default it steps forward, not backwards.  Can you try adding the following into the loop and letting us know what the output is in the console

ConsoleWrite("C:\Users\Ricardo\Desktop\RealFont\" & $i & ".png" & @CRLF)

Share this post


Link to post
Share on other sites

Actually just run your script, you need to declare $res, i.e. Global $res at the top of your script, also noticed you're using #RequireAdmin which means that you don't see anything in the console, so you would need to use MsgBox to debug.

Share this post


Link to post
Share on other sites

Oh man.. I feel so ashamed but the mistake was indeed on the "Step" parameter :\

I don't know why it worked this time, i must have typed wrong or smth.. I need to rest before continuing on this xD

Thanks both of you :) <3

Btw, i didnt get anything from ConsoleWrite now i know its from RequireAdmin. My imagesearch.au3 also has "#RequireAdmin" so it doesnt matter if i really take it off on the script, cause the one i need to delete its on the included file.

Again thanks very much for both xD

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now