Cuervo Posted January 2, 2009 Share Posted January 2, 2009 (edited) How can I call a random function from within a script? I have a file chats.au3 that has random messages in it like Func Message1() Send("{ENTER}") Sleep(200) Send("/say Thanks for coming by.") Send("{ENTER}") Sleep(200) EndFunc Func Message2() Send("{ENTER}") Sleep(200) Send("/say Wow! you're looking very sharpe today!") Send("{ENTER}") Sleep(200) EndFunc And I want to execute them from the main script using the #include <chats.au3> with somewhat of a randomness. Thanks for helping. Edited January 2, 2009 by Cuervo -Tim Link to comment Share on other sites More sharing options...
Olsson Posted January 2, 2009 Share Posted January 2, 2009 (edited) You can use the random command;Random (1, 3, -1)Random number between 1 and 3.That might get you somewhere? Edited January 2, 2009 by Olsson Link to comment Share on other sites More sharing options...
Cuervo Posted January 2, 2009 Author Share Posted January 2, 2009 (edited) You can use the random command; Random (1, 3, -1) Random number between 1 and 3. That might get you somewhere? Is this anywhere close? Global $Paused, $Showme HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{END}", "Terminate") HotKeySet("{F9}", "ShowMe") Sleep ( 400 ) Send ("{F9}") Sleep (3000) #include <Misc.au3> #include <chats.au3> $MessageNumber = Random(1, 3, -1) RandomMessage(+MessageNumber) Edited January 2, 2009 by Cuervo -Tim Link to comment Share on other sites More sharing options...
Olsson Posted January 2, 2009 Share Posted January 2, 2009 Use: [code]CODE or AutoIT codeoÝ÷ Û÷(uå¡zzh²Ø§ÊxývëjȦ¦WËZµéÛh¦·¬z{mé²Æ zÁb®ËeÉÚ©Ý¢g(uçë¢l¨º·â®ËfzËím£*.®V¬µìuÑ8^ÚºÚ"µÍÌÍÜYÜØYÙHH[ÛJKLLJBY ÌÍÜYÜØYÙHHH[[Ý[ÛJ B[ÙBY ÌÍÜYÜØYÙHH[[Ý[Û B[ÙB[Y[Y Just keep on going! Link to comment Share on other sites More sharing options...
Olsson Posted January 2, 2009 Share Posted January 2, 2009 Func func1() MsgBox("", "Function1!", "This is function 1", 0) EndFunc Func func2() MsgBox("", "Function1!", "This is function 2", 0) EndFunc Func func3() MsgBox("", "Function1!", "This is function 3", 0) EndFunc $i = 1 While $i = 1 $rMessage = Random (1, 3, 1) MsgBox ("", "Random", $rMessage, 0) If $rMessage = 1 Then func1() If $rMessage = 2 Then func2() If $rMessage = 3 Then func3() $i = $i + 1 WEnd I wrote this, works. Link to comment Share on other sites More sharing options...
MrCreatoR Posted January 2, 2009 Share Posted January 2, 2009 (edited) Try this: Call("Message" & Random(1, 2, 1)) Func Message1() ConsoleWrite("Message1() Called" & @CRLF) EndFunc Func Message2() ConsoleWrite("Message2() Called" & @CRLF) EndFuncoÝ÷ ØjÆzÛ^®Ê%ºØ¨,(ºWn±ëaɶjëh×6Message_Main(Random(1, 2, 1)) Func Message_Main($iMode) Switch $iMode Case 1 _Send_Proc("/say Thanks for coming by.") Case 2 _Send_Proc("/say Wow! you're looking very sharpe today!") EndSwitch EndFunc Func _Send_Proc($sSendData) Send("{ENTER}") Sleep(200) Send($sSendData, 1) Send("{ENTER}") Sleep(200) EndFunc Edited January 2, 2009 by MrCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
TurionAltec Posted January 2, 2009 Share Posted January 2, 2009 (edited) Store your messages in an array: dim $messages[3]=["hello", "Test message", "Third message"] send($messages[random(0,2,1)]&"{enter}") This way you can more easily add new messages without bloating your code with new functions. And it gives you more flexability if you want to read messages from a text file, or have them added with commands. Edited January 3, 2009 by TurionAltec Link to comment Share on other sites More sharing options...
Cuervo Posted January 2, 2009 Author Share Posted January 2, 2009 Func Message_Main($iMode) Switch $iMode Case 1 _Send_Proc("/say Thanks for coming by.") Case 2 _Send_Proc("/say Wow! you're looking very sharpe today!") EndSwitch EndFunc Func _Send_Proc($sSendData) Send("{ENTER}") Sleep(200) Send($sSendData, 1) Send("{ENTER}") Sleep(200) EndFunc Thanks for the great script! If I put all of that in say a func.au3 script and want to call it from the main scipt (#include <func.au3 is in my main script) how do I call it from the main script? I tried just adding this to my main script, Message_Main() that didn't do if of course. Thanks again. -Tim Link to comment Share on other sites More sharing options...
MrCreatoR Posted January 2, 2009 Share Posted January 2, 2009 If I put all of that in say a func.au3 script and want to call it from the main scipt (#include <func.au3 is in my main script) how do I call it from the main script? I tried just adding this to my main script, Message_Main() that didn't do if of course.... You need to specify the parameter, and i have a call example in my script, it seems that you missed it... Message_Main(Random(1, 2, 1)) Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Cuervo Posted January 2, 2009 Author Share Posted January 2, 2009 You need to specify the parameter, and i have a call example in my script, it seems that you missed it... Message_Main(Random(1, 2, 1)) Yes Sir you did and for some reason I totally blew by it. Thank you, it works just as intended. -Tim Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now