halex1316 3 Posted January 8, 2018 Hi there, So I was tinkering around in the F3 mission framework, and I'm slowly beginning to understand how CfgFunctions work as defined in the description.ext. There is a particular bit of code that I'm struggling to understand, however. params["_typeofUnit","_unit"]; private _faction = toLower (faction _unit); _typeofUnit = toLower _typeofUnit; _faction = toLower (param[2, (faction _unit)]); So the way this function is called is through : ["dc",this,"ctrg"] call f_fnc_assignGear; So "dc" is sent to "_typeofUnit", and this is sent to "_unit". In this case, "CTRG" is also passed, and I know (outside my knowledge of the code, I know this is a faction), but it isn't defined in the params. The line following this, private _faction = toLower (faction _unit) makes complete sense. It takes this and extracts the faction from it. _typeofUnit = toLower _typeofUnit just makes the input, like "dc" into all lower case. This also makes sense. But then, it looks like _faction is being redefined. _faction = toLower (param[2, (faction _unit)]); is what really doesn't make sense to me. I looked up "param" on the Bi Wiki and got this : Quote Extracts a single value with given index from input argument, similar to BIS_fnc_param. When used without argument, as shown in main syntax, internal variable _this, which is usually available inside functions and event handlers, is used as argument. If input argument is not an array, it will be converted to 1 element array. If extracted item of input with given index is undefined, of the wrong type or of the wrong length (if the item is an array), default value is used instead. Since Arma 3 v1.53.132691, onscreen errors are displayed for when the input is of the wrong type or size. I'm having a hard time understanding what is being said here. Can someone explain in some layman speak? Thank you very much! Share this post Link to post Share on other sites
pierremgi 4900 Posted January 8, 2018 Not the best code but OK for checking a default param as variable. The call line passes 3 parameters inside the function. The 2 first entries are declared (perhaps missing some default and/or variable types), the 3rd one is a check with the 3rd param (index 2) so, here param [2,faction (_unit)]; make the (faction _unit) by default for this 3rd param. In other word, you can't: params ["_typeofUnit","_unit",["_faction","defaultFaction"] ]; // with defaultFaction depending on _unit, in one time. You have to do that in sequence: params ["_typeofUnit","_unit"]; _faction = param [2, faction _unit]; // the tolower can be added later. So, if you don't have any clue of faction, just passing ["dc",this] call f_fnc_assignGear; the script will add the faction in accordance with this. If you pass "ctrg", then "ctrg" will be taken into account. Share this post Link to post Share on other sites
halex1316 3 Posted January 8, 2018 So you can define an optional third parameter using the format: param [2, _parameterNameHere]; ? I'm not sure I still fully understand. Because it seems like this parameter for some reason doesn't need to be defined, but the function would fail if you didn't provide the first two bits of information. What is the difference between the first ones, defined under params and the singular one defined under param? Is the parameter with an index of two just being set to a default there? And that it will take information in the index 2 spot in its place, but only if it's declared when the function is being called? ["dc",this,"gobbledeegook"] call f_fnc_assignGear; in theory, should not do anything then, since "gobbledeegook" is not a faction. Share this post Link to post Share on other sites
pierremgi 4900 Posted January 8, 2018 You're right. param and params are similar. params for an array of entries, param with index of one entry. You can't play with default values in params if they depend on each other. here the param comes after the params to play with defined object (this) and set default value (_faction) according with the defined entry (_unit). Nothing more than this adapted default value, just in case of : a default value to return if input is undefined, of the wrong type or of the wrong length (if the item is an array). Here in case of the faction stays undefined, because there is no extra check for type (string). 1 Share this post Link to post Share on other sites
halex1316 3 Posted January 8, 2018 Ahh ok. "_unit" can be defined in the params array, but because _faction needs unit to be defined i.e. faction _unit, it has to be separate in order to refer to the _unit value (whatever that might be). Thank you! That makes more sense now. Share this post Link to post Share on other sites
halex1316 3 Posted January 8, 2018 So I'm continuing work on this stuff, and I've turned the loot script I hashed out before into a function. params ["_trigger","_radius"]; _weaponArray = [ "srifle_DMR_05_blk_F", "SMG_01_F", "arifle_TRG20_F" ]; _position = getPos _trigger; _houseArray = _position nearObjects ["house",_radius]; howl_itemBoxArray = []; { _buildingPositions = [_x] call BIS_fnc_buildingPositions; { _weapon = _weaponArray select (floor(random(count _weaponArray))); _itemBox = "WeaponHolderSimulated" createVehicle [0,0,0]; _itemBox setPos _x; _itemBox addWeaponCargoGlobal [_weapon,1]; _magazines = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines"); _mag = _magazines select (floor(random(count _magazines))); _itemBox addMagazineCargoGlobal [_mag,5]; howl_itemBoxArray = howl_itemBoxArray + [_itemBox]; } forEach _buildingPositions; } forEach _houseArray; But there's a problem. I originally wanted a marker to take the position. So, in my trigger, I would type : [marker,100] call myTag_fnc_lootspawn; and nothing happens. But, I tried naming the trigger "trig1" and typing in the trigger's init: [trig1,100] call myTag_fnc_lootspawn; and it magically works. I tried changing _position = getPos _trigger; to _position = getMarkerPos _trigger; and it doesn't work. Why can't my call pass the name of a marker to my function? I realize now that the getMarkerPos requires a string, and so changing the call to : ["marker",100] call myTag_fnc_LootSpawn; works. 1 Share this post Link to post Share on other sites