Author: Grimes [3rd ID]
Author Website:

Version: 1.0

Short description: 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.

Date: 2014-01-24 09:04


Comments: (0)
Rating:



 

Grimes' Random Array Function

by
Grimes [3rd ID]


Description:
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_varformat
Also 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).

Template:
1st Call:
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;

Example applications:
1st Call:
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;

Parameters:
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.


Notes:
Feel free to send your comments or questions my way. Enjoy!


Changelog:
v1.0
- first release


Forum topic:
- BI forums




Enable javascript to be able to download from Armaholic please!



Tags: No tags