Sign in to follow this  
Followers 0
Welohabi

Random() & Array... Help Please.

5 posts in this topic

Hello,

I believe this is a simple problem... but I am very new to AutoIT and anything of this nature in general.

I have a piece of code here that checks for a certain pixel color And then clicks a specific location.

If PixelGetColor ( 770, 594 ) = 0xFFBA27 then

MouseMove( X, Y, Z)

MouseClick("left")

I would like to make an array with 12 options or maybe 12 constants. So they can be used in place of the MouseMove coordinates RANDOMLY(No repeats) in the code above. For a total of 12 Different possible mouse clicks.

1 (260,500)

2 (352,500)

3 (450,500)

4 (540,500)

5 (270,600)

6 (370,600)

7 (450,600)

8 (540,600)

9 (270,735)

10 (360,735)

11 (445,735)

12 (535,735)

Then I would like to add a Random() command to the whole code so that it plays 1-4 times, each time picking a different random coordinate.

Thanks in advance to anyone that can help..

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Sounds like you need a combination between array's and the random() function.

Edit: Didn't read the post well... But post an example first! We won't help otherwise.

I know you haven't said anything in the likes of bots and game automatisation, but this script sure sounds like that.

In that case, read this! http://www.autoitscript.com/forum/forum-2/announcement-12-game-bots-and-automation/

Edited by Triblade

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Share this post


Link to post
Share on other sites

If you make an array with the values you want, you can shuffle it and just run through it as often as you want, before re-shuffling.

There was a nice and fast algorith by another user, but for some reason all his post have been deleted and his username has been changed, so I'll link to my own, slower UDF

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Ok well this is what I have so far...

Just a Snippet from the code

dim $X1 = 270

dim $Y1 = 500

dim $X2 = 350

dim $Y2 = 600

dim $X3 = 450

dim $Y3 = 735

dim $X4 = 540

Dim $i1 = Random( 1, 12, 1)

Switch $i1

Case 1

MouseClick("left", $X1, $Y1)

Sleep (100)

Case 2

MouseClick("left", $X1, $Y2)

Sleep (100)

Case 3

MouseClick("left", $X1, $Y3)

Sleep (100)

Case 4

MouseClick("left", $X2, $Y1)

Sleep (100)

Case 5

MouseClick("left", $X2, $Y2)

Sleep (100)

Case 6

MouseClick("left", $X2, $Y3)

Sleep (100)

Case 7

MouseClick("left", $X3, $Y1)

Sleep (100)

Case 8

MouseClick("left", $X3, $Y2)

Sleep (100)

Case 9 ;Fixed

MouseClick("left", $X3, $Y3)

Sleep (100)

Case 10

MouseClick("left", $X4, $Y1)

Sleep (100)

Case 11 ;Fixed

MouseClick("left", $X4, $Y2)

Sleep (100)

Case 12

MouseClick("left", $X4, $Y3)

EndSwitch

This does what i want it to... but it just keeps repeating. I want it to select one case at a time, 1-4 times, and then continue with the rest of the script. I need to figure out a way to maybe turn this into a function, and then Put it use using something like :

If PixelGetColor ( 770, 618 ) = 0xFFBA27 then

Execute (This function) <==I want this to play randomly 1-4 times...

Thanks for your help

Edited by Welohabi

Share this post


Link to post
Share on other sites

Ok well this works... But it Selects 4 Mouse click and then moves on... How to make it randomly play $i1 - $14

dim $X1 = 270
    dim $Y1 = 500
    dim $X2 = 350
    dim $Y2 = 600
    dim $X3 = 450
    dim $Y3 = 735
    dim $X4 = 540
    Dim $i1 = Random( 1, 12, 1)
    Dim $i2 = Random( 1, 12, 1)
    Dim $i3 = Random( 1, 12, 1)
    Dim $i4 = Random( 1, 12, 1)
    
    If PixelGetColor ( 770, 618 ) = 0xFFBA27 then   
    Switch $i1
    Case 1 
        MouseClick("left", $X1, $Y1)
    Sleep (100)
    Case 2  
        MouseClick("left", $X1, $Y2)
    Sleep (100)
    Case 3  
        MouseClick("left", $X1, $Y3)
    Sleep (100)
    Case 4 
        MouseClick("left", $X2, $Y1)
    Sleep (100)
    Case 5  
        MouseClick("left", $X2, $Y2)
    Sleep (100)
    Case 6 
        MouseClick("left", $X2, $Y3)
    Sleep (100)
    Case 7  
        MouseClick("left", $X3, $Y1)
    Sleep (100)
    Case 8  
        MouseClick("left", $X3, $Y2)
    Sleep (100)
    Case 9  
        MouseClick("left", $X3, $Y3)
    Sleep (100)
    Case 10  
        MouseClick("left", $X4, $Y1)
    Sleep (100) 
    Case 11  
        MouseClick("left", $X4, $Y2)
    Sleep (100) 
    Case 12 
        MouseClick("left", $X4, $Y3)
    EndSwitch
    Sleep (500)
    Switch $i2
    Case 1  
        MouseClick("left", $X1, $Y1)
    Sleep (100)
    Case 2  
        MouseClick("left", $X1, $Y2)
    Sleep (100)
    Case 3  
        MouseClick("left", $X1, $Y3)
    Sleep (100)
    Case 4  
        MouseClick("left", $X2, $Y1)
    Sleep (100)
    Case 5  
        MouseClick("left", $X2, $Y2)
    Sleep (100)
    Case 6  
        MouseClick("left", $X2, $Y3)
    Sleep (100)
    Case 7 
        MouseClick("left", $X3, $Y1)
    Sleep (100)
    Case 8  
        MouseClick("left", $X3, $Y2)
    Sleep (100)
    Case 9 
        MouseClick("left", $X3, $Y3)
    Sleep (100)
    Case 10  
        MouseClick("left", $X4, $Y1)
    Sleep (100) 
    Case 11  
        MouseClick("left", $X4, $Y2)
    Sleep (100) 
    Case 12  
        MouseClick("left", $X4, $Y3)
    EndSwitch
    Sleep (500)
        Switch $i3
    Case 1 
        MouseClick("left", $X1, $Y1)
    Sleep (100)
    Case 2  
        MouseClick("left", $X1, $Y2)
    Sleep (100)
    Case 3 
        MouseClick("left", $X1, $Y3)
    Sleep (100)
    Case 4  
        MouseClick("left", $X2, $Y1)
    Sleep (100)
    Case 5  
        MouseClick("left", $X2, $Y2)
    Sleep (100)
    Case 6  
        MouseClick("left", $X2, $Y3)
    Sleep (100)
    Case 7  
        MouseClick("left", $X3, $Y1)
    Sleep (100)
    Case 8  
        MouseClick("left", $X3, $Y2)
    Sleep (100)
    Case 9  
        MouseClick("left", $X3, $Y3)
    Sleep (100)
    Case 10  
        MouseClick("left", $X4, $Y1)
    Sleep (100) 
    Case 11  
        MouseClick("left", $X4, $Y2)
    Sleep (100) 
    Case 12 
        MouseClick("left", $X4, $Y3)
    EndSwitch
    Sleep (500)
        Switch $i4
    Case 1  
        MouseClick("left", $X1, $Y1)
    Sleep (100)
    Case 2  
        MouseClick("left", $X1, $Y2)
    Sleep (100)
    Case 3 
        MouseClick("left", $X1, $Y3)
    Sleep (100)
    Case 4  
        MouseClick("left", $X2, $Y1)
    Sleep (100)
    Case 5  
        MouseClick("left", $X2, $Y2)
    Sleep (100)
    Case 6  
        MouseClick("left", $X2, $Y3)
    Sleep (100)
    Case 7 
        MouseClick("left", $X3, $Y1)
    Sleep (100)
    Case 8  
        MouseClick("left", $X3, $Y2)
    Sleep (100)
    Case 9 
        MouseClick("left", $X3, $Y3)
    Sleep (100)
    Case 10 
        MouseClick("left", $X4, $Y1)
    Sleep (100) 
    Case 11 
        MouseClick("left", $X4, $Y2)
    Sleep (100) 
    Case 12 
        MouseClick("left", $X4, $Y3)
    EndSwitch
    Sleep (500)
    MouseMove( 695, 600, 0)
    MouseClick("left")
    endif

Share this post


Link to post
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
Sign in to follow this  
Followers 0