Jump to content
PEscobar

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

Share this post


Link to post
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

 

Share this post


Link to post
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 (2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-03-02 - Version 1.3.5.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
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

 

Share this post


Link to post
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 (2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-03-02 - Version 1.3.5.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

@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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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

×
×
  • Create New...