Jump to content

How to start a random function?


Recommended Posts

How do I make it so a random function within the script runs. What I tried was giving all the functions the same name but with a different number at the end. In my script I added the name of each function, then the random function with a range of 1-3 since that is what each function has at the end, but this of course did not work. What is another way of doing this without using the random function?

 

HotKeySet("{F1}", "endProg")

While(1)
    camera(random(1, 3, 1)()
 WEnd

 Func camera1()
    send("{right down}")
    sleep(random(200, 1000, 1)
    send("{right up}")
 EndFunc

 Func camera2()
   send("{left down}")
   sleep(random(200, 1000, 1)
   send("{left up}")
EndFunc

Func camera3()
   send("{up down}")
   sleep(random(200, 1000, 1)
   send("{up up}")
EndFunc

Link to comment
Share on other sites

Here's one way...

HotKeySet("{F1}", "RunFunc")

While (1)
    Sleep(100)
WEnd

Func RunFunc()
    Local $aFuncs[3] = [camera1, camera2, camera3]
    Call($aFuncs[Random(0, 2, 1)])
EndFunc   ;==>RunFunc


Func camera1()
    MsgBox(0, 0, "camera1")
EndFunc   ;==>camera1

Func camera2()
    MsgBox(0, 0, "camera2")
EndFunc   ;==>camera2

Func camera3()
    MsgBox(0, 0, "camera3")
EndFunc   ;==>camera3

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Or without the need to use an array:

HotKeySet("{F1}", "RunFunc")
Global $iMaxFuncs = 3 ; highest function number
While (1)
    Sleep(100)
WEnd

Func RunFunc()
    Call("camera" & Random(1, $iMaxFuncs, 1))
EndFunc   ;==>RunFunc


Func camera1()
    MsgBox(0, 0, "camera1")
EndFunc   ;==>camera1

Func camera2()
    MsgBox(0, 0, "camera2")
EndFunc   ;==>camera2

Func camera3()
    MsgBox(0, 0, "camera3")
EndFunc   ;==>camera3

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

And without the need to use Call

HotKeySet("{F1}", "RunFunc")

While (1)
    Sleep(100)
WEnd

Func RunFunc()
    Local $aFuncs[3] = [camera1, camera2, camera3]
    $aFuncs[Random(0, 2, 1)]()
EndFunc   ;==>RunFunc


Func camera1()
    MsgBox(0, 0, "camera1")
EndFunc   ;==>camera1

Func camera2()
    MsgBox(0, 0, "camera2")
EndFunc   ;==>camera2

Func camera3()
    MsgBox(0, 0, "camera3")
EndFunc   ;==>camera3

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

PEscobar,

out of curiosity: Why do you need to run random functions?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Developers

@PEscobar, did you actually read those forumrules you were [pointed to by @Melba23?

I haven't seen the removed code but the question seems to be pretty close to your first thread!

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...