stayfrosty24 10 Posted January 9, 2015 (edited) Hi all, I'm trying to make a script with specific roles and gear. Because i'm a scripting newbie i need help from the guru's. I don't fully understand the switch statement. and how to call them in game. I've seen something similar in the F3 AssignGear script but i can't figure it out. See below what i want: AssignRole.sqf _variable = toLower (_this select 0); switch (_variable) do { case "TL" { _unit AddUniform ...; _unit AddVest ...; }; }; etc.. But how can i call this in game? In the initialization of a unit? something like [TL] call "AssignRole.sqf"? I would appreciate the help. Gr, StayFrosty24 Edited January 12, 2015 by StayFrosty24 Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted January 9, 2015 Firstly, you forgot the ":" after the case (only the default block does not require that). And secondly, switch-case is case sensitive, meaning it matters whether you've got "tl" or "TL" in your case. So, as you're doing a "toLower" before the switch, it's gotta be like this: _variable = toLower (_this select 0); switch (_variable) do { case "tl" : { _unit AddUniform ...; _unit AddVest ...; }; default {hintSilent "Not found.";}; }; Share this post Link to post Share on other sites
stayfrosty24 10 Posted January 9, 2015 Ok so how do i call this in game? I want to call the loadout of the tl what do i have to put in the init of the unit or the init.sqf file? Is it something like below? ["tl"] call "AssingRole.sqf"; can't seem to figure it out and it's giving me a headache! Gr, StayFrosty24 Share this post Link to post Share on other sites
froggyluv 2136 Posted January 9, 2015 Nul = execvm "AssignRole.sqf" ; ? Share this post Link to post Share on other sites
stayfrosty24 10 Posted January 9, 2015 froggyluv that can't be right. Because you need to pass a parameter to the script "AssignRole.sqf" so it knows that it must load the "tl" role. And that is the point that i can't figure out. If anyone could help me with this i would much appreciate it. Gr, StayFrosty24 Share this post Link to post Share on other sites
jshock 513 Posted January 9, 2015 Frog was on the right track: 0 = [paramGoesHere] execVM "script.sqf"; Share this post Link to post Share on other sites
stayfrosty24 10 Posted January 12, 2015 I'm trying but no luck here, i will post my script and hope that someone could help me here. assignrole.sqf // =================================================================================================================================== // Script: AssignRole // Author: StayFrosty24 // =================================================================================================================================== // INCLUDED FILES #include "localvars.sqf" // =================================================================================================================================== // AVAILABLE ROLES // CO // SL // MD // =================================================================================================================================== _typeunit = toLower (_this select 0); switch (_typeunit) do { case "CO" : { removeAllItems _unit; removeAllContainers _unit; removeAllWeapons _unit; removeHeadgear _unit; removeGoggles _unit; _unit unassignitem _nvg; _unit removeitem _nvg; _unit AddHeadgear _beret01; _unit AddUniform _uniform01; _unit AddVest _vest01; _unit AddMagazines [_mxgl_mag,7]; _unit AddMagazines [_mxgl_mag_tr,2]; _unit AddMagazines [_mxgl_mag_gr,5]; _unit AddWeapon _mxgl; _unit AddPrimaryWeaponItem _optic10; _unit AddPrimaryWeaponItem _snds02; _unit AddMagazines [_p45_mag, 2]; _unit AddWeapon _p45; _unit additem _map; _unit assignitem _map; _unit additem _compass; _unit assignitem _compass; _unit additem _radio; _unit assignitem _radio; _unit additem _watch; _unit assignitem _watch; [_unit, "B_A1_CO"] call BIS_fnc_setUnitInsignia; }; case "SL" : { removeAllItems _unit; removeAllContainers _unit; removeAllWeapons _unit; removeHeadgear _unit; removeGoggles _unit; _unit unassignitem _nvg; _unit removeitem _nvg; _unit AddHeadgear _helmet12; _unit addgoggles _goggle01; _unit AddUniform _uniform03; _unit AddItemToUniform _firstaid; _unit AddItemToUniform _chem_green; _unit AddItemToUniform _chem_green; _unit AddItemToUniform _grensm; _unit AddItemToUniform _grensm_green; _unit AddItemToUniform _grensm_red; _unit AddItemToUniform _p07_mag; _unit AddItemToUniform _p07_mag; //_unit AddItemToUniform ; _unit AddVest _vest04; _unit addItemToVest _mxgl_mag; _unit addItemToVest _mxgl_mag; _unit addItemToVest _mxgl_mag; _unit addItemToVest _mxgl_mag; _unit addItemToVest _mxgl_mag; _unit addItemToVest _mxgl_mag_tr; _unit addItemToVest _mxgl_mag_tr; _unit addItemToVest _mxgl_mag_gr; _unit addItemToVest _mxgl_mag_gr; _unit addItemToVest _mxgl_mag_gr; _unit addItemToVest _mxgl_mag_gr; _unit addItemToVest _mxgl_mag_gr; //_unit addItemToVest ""; _unit AddBackpack _backpack01; _unit AddItemToBackpack _mxgl_mag; _unit AddItemToBackpack _mxgl_mag; _unit AddItemToBackpack _mxgl_mag; _unit AddItemToBackpack _mxgl_mag; _unit AddItemToBackpack _mxgl_mag; _unit AddItemToBackpack _mxgl_mag_gr; _unit AddItemToBackpack _mxgl_mag_gr; _unit AddItemToBackpack _mxgl_mag_gr; _unit AddItemToBackpack _mxgl_mag_gr; _unit AddItemToBackpack _mxgl_mag_gr; //_unit AddItemToBackpack ; _unit AddMagazine [_mxgl_mag,1]; _unit AddMagazine [_mxgl_mag_gr,1]; _unit AddWeapon _mxgl; _unit AddPrimaryWeaponItem _attach01; _unit AddPrimaryWeaponItem _optic02; _unit AddMagazines [_p07_mag, 1]; _unit AddWeapon _p07; _unit additem _map; _unit assignitem _map; _unit additem _watch; _unit assignitem _watch; _unit additem _radio; _unit assignitem _radio; _unit additem _compass; _unit assignitem _compass; [_unit, "B_A1_CO"] call BIS_fnc_setUnitInsignia; }; case "MD" : { removeAllItems _unit; removeAllContainers _unit; removeAllWeapons _unit; removeHeadgear _unit; removeGoggles _unit; _unit UnassignItem _nvg; _unit RemoveItem _nvg; _unit AddHeadgear _helmet04; _unit addgoggles _goggle03; _unit AddUniform _uniform01; _unit AddItemToUniform _firstaid; _unit AddItemToUniform _chem_green; _unit AddItemToUniform _chem_green; _unit AddItemToUniform _grensm; _unit AddItemToUniform _grensm_green; _unit AddItemToUniform _p07_mag; _unit AddItemToUniform _p07_mag; _unit AddVest _vest03; _unit addItemToVest _mxc_mag; _unit addItemToVest _mxc_mag; _unit addItemToVest _mxc_mag; _unit addItemToVest _mxc_mag; _unit addItemToVest _mxc_mag; _unit addItemToVest _mxc_mag; _unit addItemToVest _mxc_mag; _unit addItemToVest _mxc_mag_tr; _unit addItemToVest _mxc_mag_tr; _unit addItemToVest _gren; _unit addItemToVest _gren; _unit addItemToVest _gren; _unit AddBackpack _backpack07; _unit AddMagazine [_mxc_mag,1]; _unit AddWeapon _mxc; _unit AddPrimaryWeaponItem _attach01; _unit AddPrimaryWeaponItem _optic03; _unit AddMagazines [_p07_mag, 1]; _unit AddWeapon _p07; _unit additem _map; _unit assignitem _map; _unit additem _compass; _unit assignitem _compass; _unit additem _watch; _unit assignitem _watch; _unit additem _radio; _unit assignitem _radio; [_unit, "B_A1_REPAIR"] call BIS_fnc_setUnitInsignia; }; }; So when in game i've tried the next commands in the init of the unit but nothing happens. null = [CO] execVM "scr\assignrole.sqf"; null = ["CO"] execVM "scr\assignrole.sqf"; please help i'm running out of options here. gr, StayFrosty24 Share this post Link to post Share on other sites
jshock 513 Posted January 12, 2015 "_unit" is undefined? Share this post Link to post Share on other sites
stayfrosty24 10 Posted January 12, 2015 I'm sorry i forgot to tell, all variables are defined in localvars.sqf included somewhere near the top of the script. Share this post Link to post Share on other sites
jshock 513 Posted January 12, 2015 I assume the file on this thread: http://forums.bistudio.com/showthread.php?187160-Include-local-variables-from-another-file But still, "_unit" is undefined, you need to include it in your script above like the following: //put this right under the _typeunit line _unit = (_this select 1); //new script call in unit's init field 0 = ["CO",this] execVM "scr/assignrole.sqf"; Share this post Link to post Share on other sites
stayfrosty24 10 Posted January 12, 2015 Yep that's the file i included. Ok i'm gonna give it a try i'll let you know if it solved the problem. gr, StayFrosty24 ---------- Post added at 07:21 ---------- Previous post was at 07:11 ---------- JShock i've tried your option but it still doesn't work. Do i have to make a function or anything for this? Share this post Link to post Share on other sites
jshock 513 Posted January 12, 2015 (edited) Oh, I missed your mistake on the cases in the switch, as Johnny brought up in his first post on this thread. Your using the toLower command, so all your cases should reflect that i.e. "CO" >> "co" "TL" >> "tl" etc. EDIT: And for future reference use -showScriptErrors in your Steam startup parameters as it will help you solve a lot of similar issues. Edited January 12, 2015 by JShock Share this post Link to post Share on other sites
stayfrosty24 10 Posted January 12, 2015 (edited) I've just tried your option and it works thank you for helping me JShock. Like i said earlier in this post i'm a scripting newbie i still have much to learn. gr, StayFrosty24 Edited January 12, 2015 by StayFrosty24 Share this post Link to post Share on other sites
jshock 513 Posted January 12, 2015 Check my edit above, and report back. Share this post Link to post Share on other sites
stayfrosty24 10 Posted January 12, 2015 I had a error in my browser so i din't see your last post :o But i have tried it and it works :) many thanks ! gr, StyaFrosty24 Share this post Link to post Share on other sites