thy_ 158 Posted February 28, 2023 How can I read a specific variable name (and not its content) between two or more files? File 0: Calling all files by THY_TAG_functions.hpp File 1: [] spawn { _team_snipers = ["classname_unit_1", "classname_unit_2"]; [_team_snipers, ...] call THY_fnc_file_2; }; File 2: THY_fnc_file_2 = { params ["_grpType", ...] // _team_snipers will be here through the parameter _grpType. // If the _grpType has the same name "_team_snipers", then... if ( _grpType == "_team_snipers" ) then {...} // return: true; }; I'm used with publicVariables like the examples below, but only for checking the public variable's content and not its name, literally: // File 1: THY_team_snipers = ["classname_unit_1", "classname_unit_2"]; publicVariable "THY_team_snipers"; // File 2: // If the _grpType has the same name "_team_snipers", then... if ( _grpType isEqualTo THY_team_snipers ) then {...} // doesnt work because other teams can got exactly the same content of team snipers. Share this post Link to post Share on other sites
Harzach 2517 Posted February 28, 2023 How is _grpType being passed to file 2? Share this post Link to post Share on other sites
thy_ 158 Posted February 28, 2023 54 minutes ago, Harzach said: How is _grpType being passed to file 2? @Harzach, my bad. The main message has been updated. Share this post Link to post Share on other sites
Harzach 2517 Posted March 1, 2023 Well, local variables are just that - local to the script where they were created. Passing a local to another script doesn't pass the identifier, just its data. This is why they must be re-declared. You might just have to pass another parameter, like a stringification of the variable: [] spawn { _team_snipers = ["classname_unit_1", "classname_unit_2"]; [_team_snipers, "_team_snipers" ...] call THY_fnc_file_2; }; THY_fnc_file_2 = { params ["_grpType", "_grpTypeVar" ...]; if ( _grpTypeVar isEqualTo "_team_snipers" ) then {...} true; }; Or you could use integers, or whatever. 3 Share this post Link to post Share on other sites
Harzach 2517 Posted March 1, 2023 I'd be super-interested to know if there is a better way to do this, BTW! Share this post Link to post Share on other sites
pierremgi 4879 Posted March 1, 2023 Not sure what the final goal is.... but you can: - set / get variables in missionNameSpace (or else space). - check if a variable is equal type of another one. see: isEqualType or isEqualTypeArray and so on. - use params with default value, expected data types... So, what for? 1 Share this post Link to post Share on other sites
thy_ 158 Posted March 1, 2023 3 minutes ago, pierremgi said: So, what for? Hi, owl @pierremgi Many things. One of them is editing the sniper team skills. The sniper team is declared and configured through FILE 1, but the functions are in FILE 2. The issue is: I got many kinds of teams by faction, and the functions are the same for all of them. Nowadays, I'm using, as @Harzach said, "stringification", but I've read about the setVariable/getVariable and I'm wondering if I should give a go deeper into both commands. I'll be honest... I've tried to understand setVariable/getVariable but for me looks the same as the example down below. CSWR_sniper_team = ["classname_1", "classname_2]; publicVariable "CSWR_sniper_team"; So why should I use setVariable/getVariable? In which case it's gold? Share this post Link to post Share on other sites
ZaellixA 383 Posted March 1, 2023 I believe, and if I am wrong please correct me, that setVariable/getVariable is a kinda recommended way to "store" data in a namespace (of which there are plenty in ArmA 3). Additionally, you could also declare the variable public through the same commands with an extra third argument like this missionNamespace setVariable ["YOU_TAG_SniperTeam", _sniperTeam, true]; Please note that I'm using the mission namespace for demonstration as I am not sure what exactly you are trying to achieve. Furthermore, I am using fictional variables and names. Generally speaking, it is a good idea to let the commands (which are made by the developers) handle all the network synchronisation and data transferring/broadcasting as this is the most efficient way, the one that is less bug and error prone and you communicate your intent clearly. 3 Share this post Link to post Share on other sites
pierremgi 4879 Posted March 2, 2023 Yes.You can also setVariable on objects or groups instead of missionNameSpace. missionNameSpace is fine for similar variable as global, or even public one: missionNameSpace ["myVar",someData,TRUE] is same as: myVar = someData; publicVariable "myVar"; but you can easily implement multiple variables like { missionNameSpace setVariable ["myIndexedVar"+str _forEachIndex, leader _x] } forEach allGroups; same as: myIndexedVar0 = leader firstgroup; myIndexedVar1 = leader secondgroup..... On the other hand, as said in my first line, you can pass variables (with same name here) on each group: { _x setVariable ["leaderOfGroup", leader _x] } forEach allGroups; you can also use/create a hashmap... 3 Share this post Link to post Share on other sites
_foley 192 Posted March 2, 2023 On 3/1/2023 at 2:52 PM, thy_ said: Hi, owl @pierremgi Many things. One of them is editing the sniper team skills. The sniper team is declared and configured through FILE 1, but the functions are in FILE 2. The issue is: I got many kinds of teams by faction, and the functions are the same for all of them. Nowadays, I'm using, as @Harzach said, "stringification", but I've read about the setVariable/getVariable and I'm wondering if I should give a go deeper into both commands. I'll be honest... I've tried to understand setVariable/getVariable but for me looks the same as the example down below. CSWR_sniper_team = ["classname_1", "classname_2]; publicVariable "CSWR_sniper_team"; So why should I use setVariable/getVariable? In which case it's gold? It sounds to me like you want to store a "preset" of some group types. If that's the case then you wanna use a hashmap: _presets = createHashMapFromArray [ ["sniper_team", ["classname_unit_1", "classname_unit_2"]], ["scout_team", ["classname_unit_1", "classname_unit_2"]], ["fireteam", ["classname_unit_3", "classname_unit_4", "classname_unit_4", "classname_unit_4"]] ]; Then if you want to do something with each preset then you can use forEach: { private _teamType = _x; private _unitClassnames = _y; systemChat format ["Team %1 is made of %2", _teamType, _unitClassnames]; } forEach _presets; This lets you differentiate between "sniper_team" and "scout_team" even though they are made of the same unit types. But again, I'm guessing here. Share some context 🙂 4 Share this post Link to post Share on other sites
thy_ 158 Posted March 9, 2023 Ok, I'm back with the solution that fits okay here. 1) fn_CSWR_population.sqf I'm creating a public variable with the sniper team units: CSWR_team_BLU_sniper = ["B_ghillie_ard_F", "B_sniper_F"]; // Max 2 units. publicVariable "CSWR_team_BLU_sniper"; 2) fn_CSWR_loadout.sqf After that, in another file, it's calling the group type (_type) as a parameter: // Exclusively for loadout replacement of sniper team [_type, _unit, "uniform", "vest", "rifle", "rifle magazine", "rifle sight/optics", "rifle rail", "rifle muzzle/supressor", "rifle bipod", "binoculars"]: [_type, _unit, "U_O_T_FullGhillie_tna_F", "", "", "", "", "", "", "", "Binocular"] call THY_fnc_CSWR_loadout_team_sniper; // empty ("") will result no changes. To remove type "removed". 3) fn_CSWR_globalFunctions.sqf Last, in the third file the script has that function (file 2) where it's comparing what came with the _teamType parameter (from the file 2). If the content is the same of the public variable "CSWR_team_BLU_sniper", keep going, otherwise, abort: THY_fnc_CSWR_loadout_team_sniper = { // This function organizes exclusively the sniper team loadout. // Returns nothing. params ["_teamType", "_unit", "_uniform", "_vest", "_rifle", "_rifleMagazine", "_rifleOptics", "_rifleRail", "_rifleMuzzle", "_rifleBipod", "_binoculars"]; private ["_isSniperTeam"]; // Initial values: _isSniperTeam = false; // Declarations: switch ( side _unit ) do { case BLUFOR: { if (_teamType isEqualTo CSWR_team_BLU_sniper) then { _isSniperTeam = true } }; case OPFOR: { if (_teamType isEqualTo CSWR_team_OPF_sniper) then { _isSniperTeam = true } }; case INDEPENDENT: { if (_teamType isEqualTo CSWR_team_IND_sniper) then { _isSniperTeam = true } }; // Civilian is not appliable here! }; // Escape: if ( !_isSniperTeam ) exitWith {}; //<CODE CODE CODE> // Return: true; }; Of course, if another team (public variable) has the same classnames and number of units in its content, it will bring an inconsistency/false positive. But it will be definitively rare to happen. 1 Share this post Link to post Share on other sites