How can I select Random images?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Carnivean
Newbie
Posts: 17
Joined: Fri Jun 10, 2011 8:04 am

How can I select Random images?

Post by Carnivean » Fri Sep 14, 2012 4:38 pm

Hi

I have a script which runs and selects an image of a padlock, there are 10 images on the screen at the same time all showing a padlock icon. The script which I wrote currently selects each of the padlocks in turn and then de-selects each of the padlocks.

What I would like to be able to do is select the padlocks randomly but can't see how to do this. Can anybody help please? I've attached my script showing what I have so far.

Label>Start_Camera_Lock
Let>k=0
Label>Padlock_Test
Letk=k+1
FindImagePos>C:\Documents and Settings\Administrator\Desktop\script bitmaps\Padlock.bmp,SCREEN,50,1,XPos,YPos,imgs
If>imgs>0
MouseMove>XPos_0,YPos_0
LClick
Else
Goto>Padlock_Deselect
EndIf
Wait>0.25
If>k=10
Goto>Padlock_Deselect
Else
Goto>Padlock_Test
EndIf
Label>Padlock_Deselect
Wait>1
MouseMove>1391,185


Let>L=0
Label>Padlock_Unlock_Test
LetL=L+1
FindImagePos>C:\Documents and Settings\Administrator\Desktop\script bitmaps\Padlock Active.bmp,SCREEN,50,1,XPos,YPos,imgs
If>imgs>0
MouseMove>XPos_0,YPos_0
LClick
Wait>0.25
Else
Goto>End
EndIf

If>L=10
Goto>End
Else
Goto>Padlock_Unlock_Test
EndIf
Label>End
//MessageModal>End of Test
Wait>2
Goto>Start_Camera_Lock


Thanks

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

Post by Marcus Tettmar » Fri Sep 14, 2012 6:25 pm

So, if you have 10 padlocks on the screen you will have two arrays - one for X coords and another for Y with 10 items in each.

So you could use the Random function to get a random number between 1 and 10 and then pull the X,Y coords for that index:

Random>10,randNum
Let>randNum=randNum+1
Let>X_coord=XPos_%randNum%
Let>Y_coord=YPos_%randNum%
MouseMove>X_coord,Y_coord
LClick

Repeat that code and it will pick a random padlock each time.

To be more generic set the range in Random to the number of matches found by FindImagePos.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Sep 14, 2012 8:02 pm

I could be wrong but I suspect what the OP really wants to do is cycle through all 10 images in a random order, not just use 10 random numbers which could repeat and not include all images. There's an old thread about shuffling here which may help.

Carnivean
Newbie
Posts: 17
Joined: Fri Jun 10, 2011 8:04 am

Post by Carnivean » Mon Sep 17, 2012 7:52 am

Thanks for the prompt help, however the padlocks are contained within a control that can be moved around anywhere on the monitor so I'm not sure that I can use the X,Y coordinates method because they will frequently change.

And thanks Me_Again cycling through all the images randomly is exactly what I'm after

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

Post by JRL » Mon Sep 17, 2012 5:00 pm

...the padlocks are contained within a control that can be moved around anywhere on the monitor...
It won't matter where the window resides, GetImagePosition> gets the position in absolute coordinates. If you're afraid someone will move the window while the script is in process, use BlockInput>

Carnivean
Newbie
Posts: 17
Joined: Fri Jun 10, 2011 8:04 am

Post by Carnivean » Tue Sep 18, 2012 8:55 am

Thanks for the help, a light bulb moment and it all makes sense now.

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