Grimes' Random Array Functionby
Grimes [3rd ID]
This function allows the user to create an array of global variables that can be called upon at any point, including while in the original array, after randomly selecting some and removing them, or after selecting them.
For instance, if you have a mission with multiple objectives to eventually be completed, you can use this function to create the array of objective names (say, to create tasks assigning the objective), then either A. Randomly select a variable in the array or B. Select and them remove that random variable from the array, ensuring no repeats in the selection (what differentiates this function from BIS_fnc_selectRandom). Check out the sample mission for hands-on clarification.
Installation / Usage:
All you need is this G_array (not the one in the mission folder). The additional info you'll need is in these comments.
Note for users wanting multiple arrays:
Because global variables are involved (because this file is executed to itself multiple times) only ONE array can be run at a time. However, to reset the function, either having emptied the first array or not, simply execute the 1st Call line again
and all variables will be redefined. If you want to run multiple "instances", having multiple arrays, you'll need to make a 2nd G_array.sqf file, and simply add another character to it and the following global variables inside it (ex, G_array2.sqf for file, G_mainarray2 for variable):
G_mainarray, G_minnum, G_maxnum, G_varformatAlso at
G_fnc_RandomArray = compile preprocessFile "G_array.sqf";you must change
the file name to whatever your 2nd file name is (ex, G_array2.sqf).
G_arraycall = [isinittrue/false, minnum, maxnum, "varformat%1", eliminatetruefalse, "onarrayemptyscript.sqf"] execVM "G_array.sqf";All Following Calls:
G_arraycall = [isinittrue/false, minnum, maxnum, "varformat%1", eliminatetruefalse, "onarrayemptyscript.sqf"] call G_fnc_RandomArray;
G_arraycall = [true, 0, 5, "Test-%1", true, "arrayempty.sqf"] execVM "G_array.sqf";All Following Calls: (located wherever to be called from):
G_arraycall = [false, 0, 5, "Test-%1", true, "arrayempty.sqf"] call G_fnc_RandomArray;
0 = List as: true , if it is the first time executing, else false .
--Note: Execute once as true to create main array, execute following times as false to begin random selection/elimination from array
1 = Minimum number to assign (inclusive)
2 = Maximum number to assign (inclusive)
3 = Format of mass-created variables in main array (must include %1 (number place holder) somewhere, keep in quotes)
4 = true/false for yes/no of whether or not to eliminate selected variable from array
5 = Filename of script to execute if function selects nil (the array is empty from elimination)
The download includes a sample mission with debug text that shows what is going on, as well as a non-debug littered file intended for actual use.
Feel free to send your comments or questions my way. Enjoy!
- first release
- BI forums
Tags: No tags