I have been working on a script to test a webpage i'm making with multiple choices. Trying to get a simplified way to select 1 of 5 pictures to click on. I used if statements for all 5 but then doesn't transfer the mouse click action. Being a before noob scripter I fugure there has to be an easier way. Saw a post about setting a variable with the choices. Any help would be appreciated.
My crack coding is as follows:
random, cats, 1, 5
ToolTip choices is %cats%
sleep 10000
if %cats% = 1
{
category=pic1.png
}
else if %cats% = 2
{
category=pic2.png
}
else if %cats% = 3
{
category=pic3.png
}
else if %cats% = 4
{
category=pic4.png
}
else if %cats% = 5
{
category=pic5.png
}
ImageSearch, FoundX, FoundY, %winx%, %winy%, %width%, %height%,*n5, %category%
ToolTip, Category %category% found at %FoundX%, %FoundY%
sleep 10000
MouseClick, left, %FoundX%+15, %FoundY%+15,5
random object selection
Re: random object selection
Remove the % signs for all your if statements.
Code: Select all
cats = 4
if %cats% = 4
MsgBox, It works using percent signs
if cats = 4
MsgBox, It works without percent signs
Re: random object selection
works now.. tyvm..
Re: random object selection
You variation parameter is in the imagename parameter and the syntax is incorrect.
Its not even possible for it to work as written in your original post.
Another issue to consider is you are not checking ErrorLevel of ImageSearch so it will always try to click even when the image is not found.
X1,Y1,X2,Y2 can be expression syntax so the percent signs arent needed there. (Its allowed to be used to comply with ahk v1)
Example of how you can optimize the script:
I would also suggest look up CoordMode in the docs.
HTH
Its not even possible for it to work as written in your original post.
Should be:ImageSearch, FoundX, FoundY, %winx%, %winy%, %width%, %height%,*n5, %category%
n is where the number goes for variation also this is put into the same parameter as the imagename.ImageSearch, FoundX, FoundY, %winx%, %winy%, %width%, %height%,*5 %category%
Another issue to consider is you are not checking ErrorLevel of ImageSearch so it will always try to click even when the image is not found.
X1,Y1,X2,Y2 can be expression syntax so the percent signs arent needed there. (Its allowed to be used to comply with ahk v1)
Example of how you can optimize the script:
Code: Select all
random, cats, 1, 5
ToolTip choices is %cats%
sleep 10000
ImageSearch, FoundX, FoundY, winx, winy, width, height,*n5 pic%cats%.png
if (ErrorLevel = 0)
{
ToolTip, Category %category% found at %FoundX%, %FoundY%
sleep 10000
MouseClick, left, %FoundX%+15, %FoundY%+15,5
}
ToolTip
HTH
Re: random object selection
Thanks for the reply XTRA.
the error checking was done prior to this part of the code. it checked for the first pic.. if it did not exists this was skipped. so it is assumed if the first pic exists the rest do also.. the changes to the syntax seem appropriate.. seeing how I don't claim to be nor want to be but am forced to be a programmer.. lol.. Again.. Thanks for the input..
the error checking was done prior to this part of the code. it checked for the first pic.. if it did not exists this was skipped. so it is assumed if the first pic exists the rest do also.. the changes to the syntax seem appropriate.. seeing how I don't claim to be nor want to be but am forced to be a programmer.. lol.. Again.. Thanks for the input..
Who is online
Users browsing this forum: Descolada, Google [Bot], inseption86, mikeyww and 419 guests