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
How can I select Random images?
Moderators: Dorian (MJT support), JRL
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
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.
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
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.
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
And thanks Me_Again cycling through all the images randomly is exactly what I'm after