Option to randomly click on different positions of an image

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
theonex
Junior Coder
Posts: 44
Joined: Thu May 10, 2012 12:32 pm

Option to randomly click on different positions of an image

Post by theonex » Wed Sep 20, 2017 10:31 am

how to set the findimagepos line as a variable, where the variable is generated randomly?
i want to achieve a random positional clicks i have attached a sample script.

Code: Select all

///////////////////////////////////////////////////////////////////////////
Let>Names[1]=FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,0,XArr,YArr,NumFound,CCOEFF
Let>Names[2]=FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
Let>Names[3]=FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,2,XArr,YArr,NumFound,CCOEFF
Let>Names[4]=FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,3,XArr,YArr,NumFound,CCOEFF
Let>Names[5]=FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,4,XArr,YArr,NumFound,CCOEFF
Let>Names[6]=FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,5,XArr,YArr,NumFound,CCOEFF
Let>Names[7]=FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,6,XArr,YArr,NumFound,CCOEFF
Let>Names[8]=FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,7,XArr,YArr,NumFound,CCOEFF
Let>Names[9]=FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,8,XArr,YArr,NumFound,CCOEFF



Let>Names_Count=9

Random>9,rndnum
Let>rndnum=rndnum+1
Let>outname=Names[%rndnum%]



Message>outname
wait>5
CloseWindow>Macro Scheduler Message
wait>2

Let>FindImagePos=outname


//Find and Left Click Center of 
FindImagePos>outname
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif
many thanks
Last edited by theonex on Wed Sep 20, 2017 8:57 pm, edited 1 time in total.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: setting findimagepos as a variable

Post by Marcus Tettmar » Wed Sep 20, 2017 5:16 pm

Really don't understand this. If you want to randomise image searches / clicks, then use FindImagePos in a loop and randomise the parameters, or maybe you want an array of needle images which you would lookup randomly (or in sequence) and pass to FindImagePos in a loop.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: setting findimagepos as a variable

Post by JRL » Wed Sep 20, 2017 7:57 pm

Not sure I understand the question either but maybe something with IncludeFromVar> that randomizes the offset position. Reading your sample code that is the one thing that changed in each line of the example.

Code: Select all

Let>vScriptCounter=0
LabelToVar>ScriptClip,vScript
IncludeFromVar>vScript

/*
ScriptClip:
Random>9,Offset
FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,%Offset%,XArr,YArr,NumFound,CCOEFF
Wait>0.1
Mousemove>XArr_0,YArr_0
Wait>1
Add>vScriptCounter,1
If>vScriptCounter>20
  Exit>0
EndIf
LabelToVar>ScriptClip,vScript
IncludeFromVar>vScript
*/

theonex
Junior Coder
Posts: 44
Joined: Thu May 10, 2012 12:32 pm

Re: setting findimagepos as a variable

Post by theonex » Wed Sep 20, 2017 8:52 pm

Thanks once again JRL it feels like your a mind reader.

My apologies Marcus i know my question wasn't really clear.

so here is what i was trying to achieve and thanks to JRL's answer i was able to fix my initial script.

Code: Select all

Let>Names[1]=0
Let>Names[2]=1
Let>Names[3]=2
Let>Names[4]=3
Let>Names[5]=4
Let>Names[6]=5
Let>Names[7]=6
Let>Names[8]=7
Let>Names[9]=8

Let>Names_Count=9

Random>9,rndnum
Let>rndnum=rndnum+1
Let>outname=Names[%rndnum%]

Message>outname
wait>5
CloseWindow>Macro Scheduler Message
wait>2

//Find and Left Click Center of 
FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,%outname%,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
wait>5
//  LClick
Endif



The concept was rather than always clicking on the center of an image how about clicking on different positions at random using using the already provided positions by MS.

thanks JRL it was your reply that helped finish the above code.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts