kennychr 16 Posted November 15, 2015 So i have been trying to shorten the loadout script ive been using for our community and ive hit a dead end. It wont compile the call for the loadout at all. The idea of this fnc was to shorten the script lenght a whole lot as we had been using a very long file with if (player == class) then {run loadout}. And i wanted to make something more sleek and faster as this is intended to run on the client. basic idea of it is: Find player class, compare player class to the array of classes, run appropriate loadout fnc. It works if i substitute the call with a hint so im guessing there is something from with my call compile format part... thanks for any help! _caller = _this select 0; _playerClass = typeOf _caller; //To be moved to separete file _playerClasses = [ "B_Soldier_F", "B_Soldier_GL_F" ]; { if (_x == _playerClass) then { call compile format ["AW_fnc_%1",_playerClass]; }; } forEach _playerClasses; 1 Share this post Link to post Share on other sites
jshock 513 Posted November 15, 2015 Do the functions your calling require any parameters to be passed in? 1 Share this post Link to post Share on other sites
killzone_kid 1332 Posted November 16, 2015 call call compile format ["AW_fnc_%1",_playerClass];1. format ["AW_fnc_%1",_playerClass]; => "AW_fnc_B_Soldier_F"2. compile format ["AW_fnc_%1",_playerClass]; => {AW_fnc_B_Soldier_F}3. call compile format ["AW_fnc_%1",_playerClass]; => call {AW_fnc_B_Soldier_F} => AW_fnc_B_Soldier_F 4. call call compile format ["AW_fnc_%1",_playerClass]; => call AW_fnc_B_Soldier_F 1 Share this post Link to post Share on other sites
moricky 211 Posted November 16, 2015 Avoid compiling on the fly as much as possible. There are better ways how to extract variable with dynamically composed name: call (missionNameSpace getVariable format ["AW_fnc_%1",_playerClass]); 3 Share this post Link to post Share on other sites
shuko 59 Posted November 16, 2015 Since it's just a loadout/gear script. Why not use the playerclass as a case in a switch-case instead? That would avoid dynamic variables. Share this post Link to post Share on other sites
kennychr 16 Posted November 16, 2015 Thanks for the input! I was aiming for a "small" fnc that read the player class and then ran the correct loadout on the player if it existed. The reason i was aiming for that is to lessen the "ohmygod so much text" for users that are not too familiar with code in the first place, i.e: x player wants to make their custom mission for a gamenight and want to have custom loadouts. English isnt my first language so its kinda hard to put down exactly what im aiming for with the function. Share this post Link to post Share on other sites