pezo89 2 Posted March 29, 2011 (edited) Hi, i where just wondering is there a to get a script starting a new function but with a random order? ie. say i have 4 functions, and i want them to fire in an random order My first thought was about using an array, and setting a random fire event on those 4 arrays, but i can't remember the random code what iv written so far regarding it, the arrays works, but for now it selects all, i want it to random select one Local $arr[4] $arr[0]=Func01() $arr[1]=func02() $arr[2]=func03() $arr[3]=func04() Local $i For $arr[04] = 0 to 4 - 1 MsgBox(0,"test",$arr) Next func Func01() MsgBox(0,"test","Fired event 01") EndFunc func Func02() MsgBox(0,"test","Fired event 02") EndFunc func Func03() MsgBox(0,"test","Fired event 03") EndFunc func Func04() MsgBox(0,"test","Fired event 04") EndFunc Edited March 29, 2011 by pezo89 Share this post Link to post Share on other sites
Felastine 0 Posted March 29, 2011 (edited) Hi You can do random by using the function Random(MIN, MAX, FLAG). FLAG 1 makes the function return an integer instead of floating point numbers. Though I wouldn't do what you're doing if I were you. Keep in mind that strictly speaking, $arr[0]=Func01() $arr[1]=Func02() $arr[2]=Func03() $arr[3]=Func04() this part is telling the computer to store the return value of FuncXX in the cell $arr[XX], which technically, is not what you are trying to do. I recommend using Switch Case or If ElseIf Else. Felastine. Edited March 29, 2011 by Felastine Share this post Link to post Share on other sites
Malkey 231 Posted March 29, 2011 (edited) This is one two ways.Global $Msg Local $arr[4] = ["Func01()", "func02()", "func03()", "func04()"] While 1 Call("Func" & StringRight("0" & Random(1, 4, 1), 2)) ;Or ;Execute($arr[Random(0, 3, 1)]) If $Msg = 1 Then Exit Sleep(10) WEnd Func Func01() $Msg = MsgBox(0, "test", "Fired event 01", 1) EndFunc ;==>Func01 Func Func02() $Msg = MsgBox(0, "test", "Fired event 02", 1) EndFunc ;==>Func02 Func Func03() $Msg = MsgBox(0, "test", "Fired event 03", 1) EndFunc ;==>Func03 Func Func04() $Msg = MsgBox(0, "test", "Fired event 04", 1) EndFunc ;==>Func04Edit: Added Call method. Edited March 29, 2011 by Malkey Share this post Link to post Share on other sites
pezo89 2 Posted March 29, 2011 Thanks alot to both of u, It is abit more complex than mine thou but works like a charm, cheers alot m8 Share this post Link to post Share on other sites
AdmiralAlkex 125 Posted March 29, 2011 Or without Execute() Global $Msg Local $arr[4] = ["Func01()", "func02()", "func03()", "func04()"] While 1 Switch Random(0, 3, 1) Case 0 Func01() Case 1 Func02() Case 2 Func03() Case 3 Func04() EndSwitch If $Msg = 1 Then Exit Sleep(10) WEnd Func Func01() $Msg = MsgBox(0, "test", "Fired event 01", 1) EndFunc ;==>Func01 Func Func02() $Msg = MsgBox(0, "test", "Fired event 02", 1) EndFunc ;==>Func02 Func Func03() $Msg = MsgBox(0, "test", "Fired event 03", 1) EndFunc ;==>Func03 Func Func04() $Msg = MsgBox(0, "test", "Fired event 04", 1) EndFunc ;==>Func04 I think this is what Felastine meant also. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Share this post Link to post Share on other sites