Jump to content
kennychr

"call compile format" doesnt seem to work ?

Recommended Posts

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;

  • Like 1

Share this post


Link to post
Share on other sites

Do the functions your calling require any parameters to be passed in?

  • Like 1

Share this post


Link to post
Share on other sites

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

  • Like 1

Share this post


Link to post
Share on other sites

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]);
  • Like 3

Share this post


Link to post
Share on other sites

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

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×