Robustcolor 30 Posted December 10, 2019 Hi, how do you guys handle a script where you have defined units and functions? Do you execVM it once or compileFinal? How does your code look like? Example Initserver; execVM "Functions\fn_DefineUnits.sqf"; or [] spawn {_code call compileFinal preprocessFileLineNumbers "Functions\fn_DefineUnits.sqf";}; same for functions.script execVM "Functions\fn_Unitfunctions.sqf"; or [] spawn {_code call compileFinal preprocessFileLineNumbers "Functions\fn_Unitfunctions.sqf";}; or something else? fn_DefineUnits; Unitpatrol = [ "uns_men_VC_mainforce_AS1","uns_men_VC_mainforce_HMG","uns_men_NVA_daccong_HMG","uns_men_NVA_daccong_AS6" ]; fn_Unitfunctions; Examplepatrol = { _grp01 = [_pos, east, Unitpatrol,[],[],[1,1],[1,1],] call BIS_fnc_spawnGroup; }; Also, is it possible use selectRandom command inside this? Unitpatrol = ["uns_men_VC_mainforce_AS1","uns_men_VC_mainforce_HMG","uns_men_NVA_daccong_HMG","uns_men_NVA_daccong_AS6"]; Share this post Link to post Share on other sites
Dedmen 2588 Posted December 10, 2019 7 hours ago, Robustcolor said: call compileFinal thats useless nonsense, final is only useful if you store the function into a variable, you never do that there. 7 hours ago, Robustcolor said: execVM "Functions\fn_DefineUnits.sqf"; or [] spawn {_code call compileFinal preprocessFileLineNumbers "Functions\fn_DefineUnits.sqf";}; execVM is equal to call compile preprocessFile if your function just sets a variable, I see no reason for "spawn" at all. Just call it without spawn. 1 Share this post Link to post Share on other sites
Robustcolor 30 Posted December 10, 2019 Call compile preprocessFile "Functions\Fn_DefineUnits.sqf"; it is then. Is there any reason for using execVM over call compile preprocessFile or vice versa in this context above? Share this post Link to post Share on other sites
pierremgi 4737 Posted December 11, 2019 There is a reason for using spawn/call some compiled preprocessFile sqf: You don't want to compile that each time you are using the code. So, at start, compile the code (preprocess sqf first), then use spawn or call in your events or loops... In other word, each time your scripts are execVMing an sqf, you recompile! A waste of resource. Note: execVM code is scheduled like spawned one. So use call when you are sure the code doesn't run any suspension (like sleep or waitUntil), except if already spawned inside an upper scheduled scope : [] spawn { call {sleep 3; hint str canSuspend}} 1 Share this post Link to post Share on other sites
Dedmen 2588 Posted December 11, 2019 16 hours ago, Robustcolor said: Is there any reason for using execVM over call compile preprocessFile or vice versa in this context above? as I said, execVM is spawn, not call. and the shortened version is slightly faster than the written out version because the longer version has more commands. But essentially you should never use either unless you really only execute a script once, as pierremgi explained above. 1 Share this post Link to post Share on other sites
Robustcolor 30 Posted December 11, 2019 Thanks @Dedmen and @pierremgi for explaining. Is it possible to use selectRandom somehow? Since calling this will choose from left to right if i call it multiple times to fill a group. Unitpatrol = ["uns_men_VC_mainforce_AS1","uns_men_VC_mainforce_HMG","uns_men_NVA_daccong_HMG","uns_men_NVA_daccong_AS6"]; Share this post Link to post Share on other sites
pierremgi 4737 Posted December 11, 2019 selectRandom or even selectRandomWeighted or deleteAt 0 for a left to right selection. Or even YourArray select _forEachIndex in a forEach loop... Depending on how do you script that in fact. Share this post Link to post Share on other sites
Robustcolor 30 Posted December 11, 2019 1 hour ago, pierremgi said: selectRandom or even selectRandomWeighted or deleteAt 0 for a left to right selection. Or even YourArray select _forEachIndex in a forEach loop... Depending on how do you script that in fact. _grp01 = [_pos, east, Unitpatrol,[],[],[1,1],[1,1],[_spawnAi,5]] call BIS_fnc_spawnGroup; _spawnAi,5 spawns 5 ai choosing from left to right from Unitpatrol array. What i would like is to get 5 random units from the array. Share this post Link to post Share on other sites
pierremgi 4737 Posted December 11, 2019 _grp01 = [_pos, east, [0,1,2,3,4] apply {selectRandom Unitpatrol},[],[],[1,1],[1,1],[]] call BIS_fnc_spawnGroup; 1 Share this post Link to post Share on other sites
Robustcolor 30 Posted December 12, 2019 13 hours ago, pierremgi said: _grp01 = [_pos, east, [0,1,2,3,4] apply {selectRandom Unitpatrol},[],[],[1,1],[1,1],[]] call BIS_fnc_spawnGroup; Error missing ] Is it possible to make it work with a variable? This below works with Selectrandom but only spawns 2 units and nothing more whatever i put in the param. I've defined 4 units in the array but still stops at 2. _test = [4,[868.277,4458.85,0]] spawn Aiteam; params [["_size",1],"_pos"]; _grp01 = [_pos,east,[_size,0] apply {selectRandom Unitpatrol},[],[],[1,1],[1,1],[]] call BIS_fnc_spawnGroup; Share this post Link to post Share on other sites
pierremgi 4737 Posted December 12, 2019 That's this f...ing bug on editor. _grp01 = [_pos, east, [0,1,2,3,4] apply {selectRandom Unitpatrol},[],[],[1,1],[1,1],[]] call BIS_fnc_spawnGroup; works. There is no error, just an invisible breaking character I had to remove. And [_size,0] apply {selectRandom Unitpatrol} will return 2 units. That's normal. Share this post Link to post Share on other sites
Robustcolor 30 Posted December 12, 2019 26 minutes ago, pierremgi said: And [_size,0] apply {selectRandom Unitpatrol} will return 2 units. That's normal. If i would like to control the size of the group with variable [_size,0] instead of typing [0,1,2,3,4] is that possible? Since now it only gives 2 units with _size. _test = [4,[868.277,4458.85,0]] spawn Aiteam; //4 is group size. params [["_size",1],"_pos"]; Share this post Link to post Share on other sites
pierremgi 4737 Posted December 12, 2019 You can test all Bis_fnc_spawnGroup syntaxes. Third parameter needs: a list of character types (Array), or an amount of characters to spawn (Number) or a CfgGroups entry (Config) - If you choose an amount of characters, you call the Bis_fnc_returnGroupComposition with no latitude on what you're spawning (only vanilla) - If you want to size, shuffle, randomize an array made of a list of character types, you just need to prepare it, but the result must be a list of character types. For example: Unitpatrol = ["uns_men_VC_mainforce_AS1","uns_men_VC_mainforce_HMG","uns_men_NVA_daccong_HMG","uns_men_NVA_daccong_AS6"]; private _spawnedArray = []; for "_i" from 0 to (4 + floor random 12) do { _spawnedArray pushBack (selectRandom unitPatrol); }; _grp01 = [_pos, east,_spawnedArray,[],[],[1,1],[1,1],[]] call BIS_fnc_spawnGroup; Share this post Link to post Share on other sites
Robustcolor 30 Posted December 17, 2019 On 12/10/2019 at 4:00 PM, Dedmen said: On 12/10/2019 at 8:25 AM, Robustcolor said: call compileFinal thats useless nonsense, final is only useful if you store the function into a variable, you never do that there. Why? What about the Anti-hack protection using compileFinal? Since my script includes global variables the compileFinal adds more protection to it? Call compileFinal preprocessFile "Functions\fn_DefineUnits.sqf"; Robust_fnc_Patrol = compileFinal preprocessFileLineNumbers "Functions\fn_Patrol.sqf"; Share this post Link to post Share on other sites
Vandeanson 1676 Posted December 17, 2019 You would want to use it to protect code assigned to a variable. The code assigned to the variable can no longer be changed/overwritten afterwards, see biki example. variablename = compileFinal.......... Your code is now stored in that variable. Trying to change that variable will no longer be possible. Your example: Call compilefinal.... -> you are calling code right away here, not storing it to a variable. Compilefinal does not add any value. Your second example seems to be fine, in my view. I think its best if you try to re-read the biki entry, i think the example there explains it well. Mind that the "storing code in variable" part is essential. Cheers Vd 2 Share this post Link to post Share on other sites
Robustcolor 30 Posted December 17, 2019 I see, thanks @Vandeanson 1 Share this post Link to post Share on other sites