jens198 0 Posted December 30, 2014 Hi, probably a stupid question. I'm trying to make my unit-equipment-setup-scripts a little more efficient. My script looks like this: unit1 call setupLeader; unit2 call setupRifleman; unit3 call setupMachingunner; exitWith{}; setupLeader = {//do all the setupcode for Leader}; setupRifleman = {//do all the setupcode for Rifleman}; setupMachingunner = {//do all the setupcode for MG}; What it does, is that unit1 ends up with the MG-equipment and unit2 and unit3 are untouched. What is my basic problem here? Jens Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted December 30, 2014 You did it the wrong way round. You need to initialize the functions first and THEN call them: setupLeader = {//do all the setupcode for Leader}; setupRifleman = {//do all the setupcode for Rifleman}; setupMachingunner = {//do all the setupcode for MG}; unit1 call setupLeader; unit2 call setupRifleman; unit3 call setupMachingunner; Share this post Link to post Share on other sites
jens198 0 Posted December 30, 2014 You did it the wrong way round. You need to initialize the functions first and THEN call them: I tried that, but goit the same result. Here's the actual code: //SETUP FUNCTIONS setupFT_Leader ={ removeAllWeapons _this; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addWeapon "RH_m16a4"; _this addMagazine "RH_15Rnd_9x19_M9"; _this addMagazine "RH_15Rnd_9x19_M9"; _this addMagazine "RH_15Rnd_9x19_M9"; _this addMagazine "RH_15Rnd_9x19_M9"; _this addWeapon "RH_m9"; }; setupFT_Rifleman ={ removeAllWeapons _this; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addWeapon "RH_m16a4"; }; setupFT_Grenadier ={ removeAllWeapons _this; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "1Rnd_HE_Grenade_shell" _this addMagazine "1Rnd_HE_Grenade_shell" _this addMagazine "1Rnd_HE_Grenade_shell" _this addMagazine "1Rnd_HE_Grenade_shell" _this addWeapon "RH_m16a4gl"; }; setupFT_Automatic_Rifleman = { removeAllWeapons _this; _this addMagazine "200Rnd_mas_556x45_T_Stanag"; _this addMagazine "200Rnd_mas_556x45_T_Stanag"; _this addMagazine "200Rnd_mas_556x45_T_Stanag"; _this addMagazine "200Rnd_mas_556x45_T_Stanag"; _this addWeapon "LMG_mas_M249_F_a"; } FT1_1_Leader call setupFT_Leader; FT1_1_Rifleman call setupFT_Rifleman; FT1_1_Automatic_Rifleman call setupFT_Automatic_Rifleman; FT1_1_Grenadier call setupFT_Grenadier; exitWith{}; Share this post Link to post Share on other sites
killzone_kid 1326 Posted December 30, 2014 exitWith{}; is not a command on its own, it is a part of the construct if () exitWith {}; As a rule of thumb, if you don't know what it does - don't use it. Share this post Link to post Share on other sites
Grumpy Old Man 3525 Posted December 30, 2014 As a rule of thumb, if you don't know what it does - don't use it. Life would be boring and discoveries wouldn't happen. Just imagine the face of the first person ever to eat a Jalapeño. On the other hand to improve performance it's good practice to put functions into the description.ext, gives various benefits. Share this post Link to post Share on other sites
jshock 512 Posted December 30, 2014 Helpful pages: https://community.bistudio.com/wiki/Function https://community.bistudio.com/wiki/Functions_Library_(Arma_3) Share this post Link to post Share on other sites
killzone_kid 1326 Posted December 30, 2014 Life would be boring and discoveries wouldn't happen.Just imagine the face of the first person ever to eat a Jalapeño. On the other hand to improve performance it's good practice to put functions into the description.ext, gives various benefits. Well, it is not like sqf is growing on a tree. There is biki which covers 99% of all commands with 95% of sensible explanation. Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted December 30, 2014 On the other hand to improve performance it's good practice to put functions into the description.ext, gives various benefits. Honestly, I still don't get what the difference between a function library and a global variable function is as you can get both from the missionNamespace by their name. Share this post Link to post Share on other sites
epicgoldenwarrior 11 Posted December 30, 2014 It would help this guy to tell him what to do rather than argue about other things ^.^ Share this post Link to post Share on other sites
killzone_kid 1326 Posted December 30, 2014 It would help this guy to tell him what to do rather than argue about other things ^.^ If you know how to help this guy, please do, because there is nothing wrong with his code apart from last exitwith{} which would obviously produce an error he cannot see because he probably has no error reporting enabled. Share this post Link to post Share on other sites
austin_medic 109 Posted December 30, 2014 I tried that, but goit the same result. Here's the actual code: //SETUP FUNCTIONS setupFT_Leader ={ removeAllWeapons _this; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addWeapon "RH_m16a4"; _this addMagazine "RH_15Rnd_9x19_M9"; _this addMagazine "RH_15Rnd_9x19_M9"; _this addMagazine "RH_15Rnd_9x19_M9"; _this addMagazine "RH_15Rnd_9x19_M9"; _this addWeapon "RH_m9"; }; setupFT_Rifleman ={ removeAllWeapons _this; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addWeapon "RH_m16a4"; }; setupFT_Grenadier ={ removeAllWeapons _this; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "1Rnd_HE_Grenade_shell" _this addMagazine "1Rnd_HE_Grenade_shell" _this addMagazine "1Rnd_HE_Grenade_shell" _this addMagazine "1Rnd_HE_Grenade_shell" _this addWeapon "RH_m16a4gl"; }; setupFT_Automatic_Rifleman = { removeAllWeapons _this; _this addMagazine "200Rnd_mas_556x45_T_Stanag"; _this addMagazine "200Rnd_mas_556x45_T_Stanag"; _this addMagazine "200Rnd_mas_556x45_T_Stanag"; _this addMagazine "200Rnd_mas_556x45_T_Stanag"; _this addWeapon "LMG_mas_M249_F_a"; } FT1_1_Leader call setupFT_Leader; FT1_1_Rifleman call setupFT_Rifleman; FT1_1_Automatic_Rifleman call setupFT_Automatic_Rifleman; FT1_1_Grenadier call setupFT_Grenadier; exitWith{}; Isn't it useless to exit the script yourself at the end of the code since the script will destory itself once it has no more code to read? Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted December 30, 2014 Isn't it useless to exit the script yourself at the end of the code since the script will destory itself once it has no more code to read? That's what KK discribed twice already, including that exitWith requires an if-statement to not produce an error. ^_^ Share this post Link to post Share on other sites
epicgoldenwarrior 11 Posted December 30, 2014 Ok, here I go Instead of adding each individual mag, write: _this addMagazines ["30rnd_556x45_STANAG", 5]; DONE. Never said it had to be on topic. Share this post Link to post Share on other sites
Lala14 135 Posted December 30, 2014 his missing a ';' at _this addWeapon "LMG_mas_M249_F_a"; } Share this post Link to post Share on other sites
Grumpy Old Man 3525 Posted December 30, 2014 I tried that, but goit the same result. Here's the actual code: //SETUP FUNCTIONS setupFT_Leader ={ removeAllWeapons _this; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addWeapon "RH_m16a4"; _this addMagazine "RH_15Rnd_9x19_M9"; _this addMagazine "RH_15Rnd_9x19_M9"; _this addMagazine "RH_15Rnd_9x19_M9"; _this addMagazine "RH_15Rnd_9x19_M9"; _this addWeapon "RH_m9"; }; setupFT_Rifleman ={ removeAllWeapons _this; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addWeapon "RH_m16a4"; }; setupFT_Grenadier ={ removeAllWeapons _this; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "1Rnd_HE_Grenade_shell" _this addMagazine "1Rnd_HE_Grenade_shell" _this addMagazine "1Rnd_HE_Grenade_shell" _this addMagazine "1Rnd_HE_Grenade_shell" _this addWeapon "RH_m16a4gl"; }; setupFT_Automatic_Rifleman = { removeAllWeapons _this; _this addMagazine "200Rnd_mas_556x45_T_Stanag"; _this addMagazine "200Rnd_mas_556x45_T_Stanag"; _this addMagazine "200Rnd_mas_556x45_T_Stanag"; _this addMagazine "200Rnd_mas_556x45_T_Stanag"; _this addWeapon "LMG_mas_M249_F_a"; } FT1_1_Leader call setupFT_Leader; FT1_1_Rifleman call setupFT_Rifleman; FT1_1_Automatic_Rifleman call setupFT_Automatic_Rifleman; FT1_1_Grenadier call setupFT_Grenadier; exitWith{}; Oh wow, that's a huge wall which is easy to avoid when using a simple BIS function. instead of: _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addMagazine "30rnd_556x45_STANAG"; _this addWeapon "RH_m16a4"; _this addMagazine "RH_15Rnd_9x19_M9"; _this addMagazine "RH_15Rnd_9x19_M9"; _this addMagazine "RH_15Rnd_9x19_M9"; _this addMagazine "RH_15Rnd_9x19_M9"; _this addWeapon "RH_m9"; you could use an easier to read version like this: [_this,"RH_m16a4",10] call BIS_fnc_addWeapon; [_this,"RH_m9",4] call BIS_fnc_addWeapon; How's two lines instead of 16? Share this post Link to post Share on other sites
jens198 0 Posted December 31, 2014 [_this,"RH_m16a4",10] call BIS_fnc_addWeapon; [_this,"RH_m9",4] call BIS_fnc_addWeapon; How's two lines instead of 16? Thanks for your input guys. I did a lot of reading on those functions that already come along with ArmA. Even as I can make my setup scripts much smarter with those functions, I'm still interested in solving my original problem. What I want to do, is to define a function in a script and use it in the same script. setupFT_Leader ={ [_this,"RH_m16a4",10] call BIS_fnc_addWeapon; [_this,"RH_m9",4] call BIS_fnc_addWeapon; }; setupFT_Grenadier ={ [_this,"RH_m16a4gl",10] call BIS_fnc_addWeapon; }; setupFT_Automatic_Rifleman ={ [_this,"LMG_mas_M249_F_a",10] call BIS_fnc_addWeapon; }; setupFT_Rifleman ={ [_this,"RH_m16a4",5] call BIS_fnc_addWeapon; }; FT1_1_Leader call setupFT_Leader; FT1_1_Grenadier call setupFT_Grenadier; FT1_1_Automatic_Rifleman call setupFT_Automatic_Rifleman; FT1_1_Rifleman call setupFT_Rifleman; Running this code, I get the following in the RPT file: 12:42:33 Error in expression <//FT1_1_Rifleman call setupFT_Rifleman;> 12:42:33 Error position: <//FT1_1_Rifleman call setupFT_Rifleman;> 12:42:33 Error Invalid number in expression 12:42:33 Error in expression <FT1_1_Leader call setupFT_Leader;> 12:42:33 Error position: <setupFT_Leader;> 12:42:33 Error Undefined variable in expression: setupft_leader 12:42:33 Error in expression <FT1_1_Grenadier call setupFT_Grenadier;> 12:42:33 Error position: <setupFT_Grenadier;> 12:42:33 Error Undefined variable in expression: setupft_grenadier 12:42:33 Error in expression <FT1_1_Automatic_Rifleman call setupFT_Automatic_Rifleman;> 12:42:33 Error position: <setupFT_Automatic_Rifleman;> 12:42:33 Error Undefined variable in expression: setupft_automatic_rifleman Jens Share this post Link to post Share on other sites
jshock 512 Posted December 31, 2014 Just because it was never asked, but just to be certain, are you execVM this script? Share this post Link to post Share on other sites
Beerkan 71 Posted December 31, 2014 Replace FT1_1_Leader call setupFT_Leader; FT1_1_Grenadier call setupFT_Grenadier; FT1_1_Automatic_Rifleman call setupFT_Automatic_Rifleman; FT1_1_Rifleman call setupFT_Rifleman; with [FT1_1_Leader,"setupFT_Leader",nil,true] spawn BIS_fnc_MP; [FT1_1_Grenadier,"setupFT_Grenadier",nil,true] spawn BIS_fnc_MP; [FT1_1_Automatic_Rifleman,"setupFT_Automatic_Rifleman",nil,true] spawn BIS_fnc_MP; [FT1_1_Rifleman,"setupFT_Rifleman",nil,true] spawn BIS_fnc_MP; Share this post Link to post Share on other sites
jens198 0 Posted December 31, 2014 Just because it was never asked, but just to be certain, are you execVM this script? NO!! I only used "exec" and not "execVM"!! That did the trick. Thanks mate. No it works as it is supposed to be. Jens Share this post Link to post Share on other sites
MrPineapple 11 Posted December 31, 2014 (edited) Those functions should be local variables not global variables if they are only used in that script. You have, which are global variables: setupLeader = {}; setupRifleman = {}; setupMachingunner = {}; You can use instead; these functions will only be local to this script: _setupLeader = {}; _setupRifleman = {}; _setupMachingunner = {}; So put an underscore in front of those function variables if they are only needed in that one script. edit: nevermind I didn't see that you actually do want the functions global because your using 'bis_fnc_mp'. You said in the title functions inside scripts. So I interpreted it as you wanting local functions. Edited December 31, 2014 by MrPineapple Share this post Link to post Share on other sites