Sign in to follow this  
Followers 0
Cuervo

Calling a random function from with script?

10 posts in this topic

#1 ·  Posted (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 by Cuervo

-Tim

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You can use the random command;

Random (1, 3, -1)

Random number between 1 and 3.

That might get you somewhere?

Edited by Olsson

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by Cuervo

-Tim

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by MrCreatoR

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by TurionAltec

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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))

:)


Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

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

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