thedubl 43 Posted October 8, 2015 Hello, Hope all are well. I have run into a problem in a script. In the script the there is a piece that I am working to create some AI defenders for a random task.... For some reason this only runs for the first "_manType". I have not been able to see my mistake. I am sure I am missing something silly. Ideas? Thanks, dubl /*****************************************************************Create defenders***************************************************************/{_manType = _x select 0;_manName = _x select 1;_man = _manType createVehicle getMarkerPos "defend1"; if (_manName != "") then { (_man select 0) setVehicleVarName _manName; missionNamespace setVariable [_manName, (_man select 0)]; };}Foreach[["B_soldier_LAT_F", "man1"],["B_soldier_AR_F", "man2"],["B_soldier_exp_F", "man3"],["B_medic_F", "man4"]]; Share this post Link to post Share on other sites
killzone_kid 1331 Posted October 8, 2015 _man is object therefore it cannot be (_man select 0) Using -showScriptErrors in launch params would have shown you where the error was if you do not fancy checking .rpt every time Share this post Link to post Share on other sites
thedubl 43 Posted October 8, 2015 Ah man! Thanks. I will fix it after work! I will use the -showScriptErrors from now on too. Thanks! dubl Share this post Link to post Share on other sites
tacticalnuggets 24 Posted October 8, 2015 Yeah, first thing I saw was the object _man being treated as an array. A good form of practice is to put the data type of the variable at the end like so. _manObj = herp derp; _manObject = herp derp; Then use terms for indexes like so //very consistent with mathematics notation _i = 0; _j = 0; _k = 0; //explicit _index = 0; //if you have more than 3 _a = 0; _b = 0; _c = 0; //.... Sometimes I use all capital local variables to denote number id's for switch statements. _MY_FIRST_ID = 1; _MY_SECOND_ID = 2; _MY_THIRD_ID = 3; Many users use this for local functions _fnc_Myfunc = { //code... }; There is more, but its wise to look at the latest trends to stay in touch with standards. Share this post Link to post Share on other sites
thedubl 43 Posted October 9, 2015 Thanks ! I got all of this working. I am going to swtich it to use createunit array instead... https://community.bistudio.com/wiki/createUnit_array. Once that is working I will post the snippet up for others. dubl Share this post Link to post Share on other sites