SkogUlv 0 Posted December 27, 2006 If I have an array like : Dummy = [ "Dummy1.sqs", "Dummy2.sqs", "Dummy3.sqs" ] And I wanna execute one of them randomly using say : [ player ] exec "dummy?.sqs" How do I solve this puzzle so I can execute a script, based on the name from an array. Share this post Link to post Share on other sites
foobee 0 Posted December 27, 2006 Hello, you can randomize the select in the array : <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _array = ["script_A.sqf","script_B.sqf","script_Z.sqf"]; _script = _array select (random ((count _array) - 1)); [...] execVM _script; ('old' syntax below) <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _array = ["script_A.sqf","script_B.sqf","script_Z.sqf"] _script = _array select (random ((count _array) - 1)) [...] exec _script 'Random' returns real values, you can check about index rounding here. This code won't work on an empty array Cheers Share this post Link to post Share on other sites
ColonelSandersLite 0 Posted December 28, 2006 If you really want to do this: [ player ] exec "dummy?.sqs" You don't need an array to do it. You do need a get random integer function though. You can find a couple of these on ofpec including mine in here. I believe mine works without modification in arma, let me know if I'm wrong should you try it. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _int = [X, Y] call PickRandomIntegerFunction; _scriptToExecute = format["dummy%1.sqs", _int]; [ player ] exec _scriptToExecute; Note that I haven't actually tried that code, but it should work pretty well. It may not be 100% syntaxtually accurate though. Share this post Link to post Share on other sites