Jump to content

Image Search Problem?


Reptos
 Share

Recommended Posts

Why is it giving me and error when i do the ImageSearch, The bmp is in the same location as the Script so why is it doing this?

 

Error Below

$result = _ImageSearch('gift.bmp',1,$x,$y,100)
$result = _ImageSearch('gift.bmp',1,^ ERROR

Script Below 

#include <ImageSearch.au3>


HotKeySet("{ENTER}","start")





While 1
   Sleep(1)
   WEnd





Func start()
   While 1
     $result = _ImageSearch('gift.bmp',1,$x,$y,100)
      If $result = 1 Then
         MouseClick("Left",$x,$y,1,10)
      EndIf

   WEnd
EndFunc

 

 

Edited by Melba23
Added tags
Link to comment
Share on other sites

$x and $y aren't declared.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

What error are you getting?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

That's the entire error message?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

That's the entire error message?

Sorry 

 

"C:\Users\Owner\Desktop\Autoit Stuff\Ourworld\BMP\nestin.au3" (17) : ==> Variable used without being declared.:
$result = _ImageSearch("gift.bmp",1,$x,$y,100)
$result = _ImageSearch("gift.bmp",1,^ ERROR
>Exit code: 1    Time: 2.769

 

Link to comment
Share on other sites

  • Developers

So what about showing the script that gets the error with the lines defining $x and $y  as you clearly have done something wrong? ;)

Jos

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

This is the whole Script : 

#include <ImageSearch.au3>

HotKeySet("{ENTER}","start")




While 1
   Sleep(1)
   WEnd



$x = 0
$y = 0

Func start()
  While 1
      WinActivate("ourWorld")
     $result = _ImageSearch("gift.BMP",1,$x,$y,100)
      If $result = 1 Then
         MouseClick("Left",$x,$y,1,10)
      EndIf

   WEnd
EndFunc

 

Edited by Melba23
Removed quote and added tags
Link to comment
Share on other sites

  • Developers

So did you try to understand how your script is running and what would be a logical location to put those 2 lines?
Actually the whole script doesn't make any sense looking at the logic.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Scripts are ran from top to bottom, unless there's a function call in between.

In your script, starting from the top, it goes like this.

; step 1 add the contents of the ImageSearch UDF and execute anything that's not contained inside a function
#include <ImageSearch.au3>
; step 2 Set the hotkey
HotKeySet("{ENTER}", "start")


; Step 3 Start the While loop
While 1
; Step 4 Sleep for 10ms (the minimum amount you can sleep for)
    Sleep(1)
; Step 5 Go back to the top of the While loop (Step 3)
WEnd
; Step 6 There is no step 6 because you're stuck inside the While loop
$x = 0
$y = 0
; Function called by the HotKey
Func start()
    ; Step 1 Start the While loop
    While 1
        ; Step 2 Wait for the windows titled "ourWorld" to be the active window - You may never leave this step if the window never becomes active
        WinActivate("ourWorld")
        ; Step 3 Search for the image "gift.bmp" and assign the return to $result
        $result = _ImageSearch("gift.BMP", 1, $x, $y, 100)
        ; Step 4 Check to see if $result is -1
        If $result = 1 Then
            ; Step 5 If $result = -1 then click the left mouse button at $x and $y
            MouseClick("Left", $x, $y, 1, 10)
        EndIf
        ; step 6 Go back to step 1 forever.
    WEnd
EndFunc   ;==>start

2 errors in your script, maybe 3, First $x and $y aren't declared because they're after the first While loop, Second you have no way to get out of the function call because it's running another endless loop there. 3rd optionally, you don't put a timeout on the WinWaitActive so it could be sitting there forever before the imagesearch ever runs. A 4th optional error is that you have no way of stopping the script from running for as long as the computer is on.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

The error im getting now is 

if $result[0]="0" then return 0
if $result^ ERROR





; step 1 add the contents of the ImageSearch UDF and execute anything that's not contained inside a function
#include <ImageSearch.au3>
; step 2 Set the hotkey
HotKeySet("{ENTER}", "start")


; Step 3 Start the While loop

; Step 6 There is no step 6 because you're stuck inside the While loop

          $x = 0
         $y = 0

While 1
   Sleep(1)
   WEnd

; Function called by the HotKey

Func start()
    ; Step 1 Start the While loop
    While 1
        ; Step 2 Wait for the windows titled "ourWorld" to be the active window - You may never leave this step if the window never becomes active
        WinActivate("ourWorld")

        ; Step 3 Search for the image "gift.bmp" and assign the return to $result
        $result = _ImageSearch("gift.BMP", 1, $x, $y, 100)
        ; Step 4 Check to see if $result is -1
        If $result = 1 Then
            ; Step 5 If $result = -1 then click the left mouse button at $x and $y
            MouseClick("Left", $x, $y, 1, 10)
        EndIf

        ; step 6 Go back to step 1 forever.
    WEnd

EndFunc   ;==>start

 

Edited by Melba23
Removed quote and added tags
Link to comment
Share on other sites

  • Moderators

Reptos,

When you post code please use Code tags - see here how to do it.  Then you get a scrolling box and syntax colouring as you can see in the other posts.

And when you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - we know what we wrote and it just pads the thread unnecessarily.

Thanks for your cooperation,

M23

 

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Please use code tags when posting code, it looks like "<>" in the tool bar of the reply screen.

Also, don't quote what I posted, I know what I wrote and it's harder to follow the thread with unnecessary quoting.

 

That error you posted looks like it's coming from the UDF and not your script. Try adding a local declaration in front of your $result variable, as you may be overwriting an array inside the UDF because you don't declare your variables properly.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Developers

Obviously i don't understand so why ask me... That is kinda why i'm here FOR HELP! Come'on Jos use your brain.

I am sorry, but you have been in this mode since the day to signed up 10 days ago, and are not showing any initiative to understand what you are doing and seems to keep on asking the same thing.

Start reading and learning and you will get help. ;)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I am sorry, but you have been in this mode since the day to signed up 10 days ago, and are not showing any initiative to understand what you are doing and seems to keep on asking the same thing.

Start reading and learning and you will get help. ;)

Jos

Jos you're those type of people that think they are Mr know it all. I came here to get help. I'm new at all of this literally. You stated " are are not showing any initiative " please choose your words wisely because that did not make any since. Maybe you need to "Start Reading" and learn how to type correctly. Now my intention was not to come here and argue it was simply to come and learn things that i did not know. Some people have certain learning deference's, you may learn quicker than i do that is why i keep asking for help maybe on the same topic. I'm done arguing with you for now have a great day!

Link to comment
Share on other sites

  • Developers

Good to see you are taking the time to read and properly articulate your sentences. As to the content of it:  It is clear you do not know what you are saying but will not hold it against you. ;)

Good luck with your scripting endeavors.

Jos    

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

×
×
  • Create New...