scottb613 283 Posted September 30, 2016 Hi Folks, I know how to do the loop and increment counters and such - however - how do I increment the name of a "variable" on each run through the loop ? _var1, _var2, _var3, _varx ??? If I use the "format" command trying to create the var name - it turns it into a "string" instead of a var - no ? Thanks... Regards, Scott Sent from my iPad using Tapatalk Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted September 30, 2016 What do you want to increase? A string or a number? You're confusing data types with variables. Cheers Share this post Link to post Share on other sites
davidoss 552 Posted September 30, 2016 {compile format ['_var%1',_forEachindex]} foreach _this _var0 _var1 _var2... Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted September 30, 2016 That wouldn't make much sense if there's no _var0 - _varN defined anywhere. Cheers Share this post Link to post Share on other sites
scottb613 283 Posted September 30, 2016 HI Folks, Hmm - yeah - I think "compile" will do the trick - I've also just seen it referenced preceded by "call"... The wiki is a bit vague though... Yeah - I'm just trying to increment the variable name... The first time through the loop I want to use "_moo1" - the second time through the loop I want to use "_moo2" and so on... Let me try this - much appreciated - gents... Regards, Scott Sent from my iPad using Tapatalk Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted September 30, 2016 Just out of curiosity, can you post the script you want to use it in? There's most likely a more convenient approach to solve your problem. Cheers Share this post Link to post Share on other sites
R3vo 2654 Posted September 30, 2016 There is actually a BIS function for that. https://community.bistudio.com/wiki/BIS_fnc_counter Share this post Link to post Share on other sites
scottb613 283 Posted September 30, 2016 Hi Folks, Sure - the gist of this is to launch (4) troop laden slicks to an LZ - empty the slicks - and they return to base... I am working on adding a feature where you can add up to six markers to create a user defined path to the LZ... So I'm trying to increment the various vars holding defined waypoints as I loop through it... This part is not working yet... This is my first attempt at Arma scripting - so I'm certainly open to feedback... I'm looking at that BIS function - I'm not sure I understand what it's doing - I'll read it a few more times.... Appreciate the help... //============================// // SLICKS - SCO Launch Script // //============================// // Given: Helicopters preloaded with infantry squads - units named in assets. // Given: Helicopters will assault LZ with defined helipads - drop troops - RTB to home helipads. // Assets: (s1 - player) // Assets: (slick1 - slick helo) (slick2 - slick helo) (slick3 - slick helo) (slick4 - slick helo) // Assets: (chalk1 - inf squad) (chalk2 - inf squad) (chalk3 - inf squad) (chalk4 - inf squad) // Assets: (LzPad1 - lz hpad) (LzPad2 - lz hpad) (LzPad3 - lz hpad) (LzPad4 - lz hpad) // Assets: (BsPad1 - base hpad) (BsPad2 - base hpad) (BsPad3 - base hpad) (BsPad4 - base hpad) hint "Slicks GO"; private ["_slkG1","_slkG2","_slkG3","_slkG4","_lzPad1","_lzPad2","_lzPad3","_lzPad4","_bsPad1","_bsPad2","_bsPad3","_bsPad4","_wplz","_wpip","_wpul","_wpmv","_wpbs","_arrX","_arrY","_arrZ","_arrXn","_arrYn","_wpslk1","_wpslk2","_wpslk3","_chktmp","_chkG1","_chkG2","_chkG3","_chkG4","_strlnd","_strhgt","_wpchk1","_wpchk2","_ipdis","_ipoff","_ScoHeloWp","_dist","_offs","_strp","_endp","_head","_mkrman","_mkrcnt","_mkrarr","_mkXpam","_mkYpam","_m1","_m2","_m3","_m4","_m5","_m6"]; // var - slick groups // _slkG1 = group slick1; _slkG2 = group slick2; _slkG3 = group slick3; _slkG4 = group slick4; // var - chalk groups // _chkG1 = group chalk1; _chkG2 = group chalk2; _chkG3 = group chalk3; _chkG4 = group chalk4; // var - lz landing pads // _lzPad1 = getPos LzPad1; _lzPad2 = getPos LzPad2; _lzPad3 = getPos LzPad3; _lzPad4 = getPos LzPad4; // var - waypoints // _wplz = nil; _wpip = nil; _wpul = nil; _wpmv = nil; _wpbs = nil; _wpslk1 = nil; _wpslk2 = nil; _wpslk3 = nil; _wpchk1 = nil; _wpchk2 = nil; // var - home landing pads // _bsPad1 = getPos BsPad1; _bsPad2 = getPos BsPad2; _bsPad3 = getPos BsPad3; _bsPad4 = getPos BsPad4; // var - direction/distance from LZ to BASE for IP // _ipdis = nil; // var - position array // _arrX = nil; _arrY = nil; _arrZ = nil; _arrXn = nil; _arrYn = nil; //var - position calculations // _head = nil; _dist = nil; _offs = nil; _strp = nil; _endp = nil; // var - manual marker positions // _mkrman = 0; _mkrcnt = 0; _mkrarr = nil; _mkXpam = nil; _mkYpam = nil; _m0 = nil; _m1 = getMarkerPos "m1"; _m2 = getMarkerPos "m2"; _m3 = getMarkerPos "m3"; _m4 = getMarkerPos "m4"; _m5 = getMarkerPos "m5"; _m6 = getMarkerPos "m6"; sleep 10; // func - calulate positions - args [distance, angle offset, start point, end point] // _ScoHeloWp = { _dist = _this select 0; _offs = _this select 1; _strp = _this select 2; _endp = _this select 3; _arrX = _endp select 0; _arrY = _endp select 1; _arrZ = _endp select 2; _head = [_endp, _strp] call BIS_fnc_dirTo; _head = _head + _offs; if (_head > 360) then {_head = _head - 360}; if (_head < 0) then {_head = _head + 360}; _arrXn = ((sin _head) * _dist) + _arrX; _arrYn = ((cos _head) * _dist) + _arrY; [_arrXn,_arrYn,_arrZ]; }; // test for the existance of manual waypoints - m1,m2,m3,m4,m5,m6 // { _mkXpam = _x select 0; _mkYpam = _x select 1; if ((_mkXpam > 0 || _mkYpam > 0) && _mkrman == 0) then { _mkrarr = _mkrarr + _x; _mkrman = 1; }; } foreach [_m1,_m2,_m3,_m4,_m5,_m6]; // array of manual markers // _mkrcnt = count _mkrarr; // slick delete all waypoints // while {(count (waypoints _x)) > 0} do { deleteWaypoint ((waypoints _x) select 0); }; // troop delete all waypoints // while {(count (waypoints _chktmp)) > 0} do { deleteWaypoint ((waypoints _chktmp) select 0); }; { // get slick LZ and Base waypoint - get respective troop var // switch (_x) do { case _slkG1: { _wplz = _lzPad1; _wpbs = _bsPad1; _chktmp = _chkG1; _strlnd = "slick1 land 'LAND'"; _strhgt = "slick1 flyInHeight 20"; _formdis = 25; _formoff = 180; }; case _slkG2: { _wplz = _lzPad2; _wpbs = _bsPad2; _chktmp = _chkG2; _strlnd = "slick2 land 'LAND'"; _strhgt = "slick2 flyInHeight 20"; _formdis = 25; _formoff = 45; }; case _slkG3: { _wplz = _lzPad3; _wpbs = _bsPad3; _chktmp = _chkG3; _strlnd = "slick3 land 'LAND'"; _strhgt = "slick3 flyInHeight 20"; _formdis = 25; _formoff = -45; }; case _slkG4: { _wplz = _lzPad4; _wpbs = _bsPad4; _chktmp = _chkG4; _strlnd = "slick4 land 'LAND'"; _strhgt = "slick4 flyInHeight 20"; _formdis = 25; _formoff = 0; }; }; // if manual waypoint exist - else auto waypoint // if (_mkrcnt > 0) then { _counter = 0; _m0 = getpos _x; _helogrp = _x; _formstr = _m0; _formend = _m1; { _wpform = [_formdis,_formoff,_formstr,_formend] call _ScoHeloWp; _wpslik = _helogrp addWaypoint [_wpform,0]; _counter = _counter + 1; } foreach _mkrarr; } else { // get LZ position and break down array // _arrX = _wplz select 0; _arrY = _wplz select 1; _arrZ = _wplz select 2; // get slick IP waypoint - bearing relative to start posit - COS and SIN reversed for BIS // _ipoff = -50; _wpip = [_ipdis,_ipoff,_wpbs,_wplz] call _ScoHeloWp; // create slick waypoints // _wpslk1 = _x addWaypoint [_wpip,0]; _wpslk2 = _x addWaypoint [_wplz,0]; _wpslk3 = _x addWaypoint [_wpbs,0]; _wpslk1 setWaypointType "MOVE"; _wpslk2 setWaypointType "TR UNLOAD"; _wpslk2 setWaypointSpeed "LIMITED"; _wpslk3 setWaypointType "MOVE"; _wpslk3 setWaypointSpeed "NORMAL"; _wpslk3 setWaypointBehaviour "CARELESS"; _wpslk3 setWaypointCompletionRadius 50; _wpslk3 setWaypointStatements ["true", _strlnd]; }; // get troops UNLOAD waypoint // _arrXn = _arrX + 5; _wpul = [_arrXn,_arrY,_arrZ]; // get troops MOVE waypoint // _arrXn = _arrX - 50; _arrYn = _arrY + 50; _wpmv = [_arrXn,_arrYn,_arrZ]; // create troops waypoints // _wpchk1 = _chktmp addWaypoint [_wpul,0]; _wpchk2 = _chktmp addWaypoint [_wpmv,0]; _wpchk1 setWaypointType "GETOUT"; _wpchk2 setWaypointType "MOVE"; _wpchk2 setWaypointBehaviour "COMBAT"; _wpchk2 setWaypointSpeed "LIMITED"; _wpchk2 setWaypointFormation "WEDGE"; // sync unload waypoints - helo and troops // _wpslk2 synchronizeWaypoint _wpchk1; // sleep for spacing of slicks // sleep 15; } foreach [_slkG1, _slkG2, _slkG3, _slkG4]; Regards,Scott Sent from my iPad using Tapatalk Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted September 30, 2016 Why not make a function that works for one chopper/unit and execute it multiple times? Cheers Share this post Link to post Share on other sites
scottb613 283 Posted September 30, 2016 Thanks Grumpy - I'll give it a shot... The distilled version of what I'm trying to do for markers (m1-m6)... I'm on my iPad so I can't test now but I think this may be close... _wpcnt = 0; _m0 = getpos _slick; _helogrp = _slick; { _formstr = call compile format ["_m%1",_wpcnt]; _wpplus = _wpcnt + 1; _formend = call compile format ["_m%1",_wpplus]; _wpform = [_formdis,_formoff,_formstr,_formend] call _ScoHeloWp; _wpslik = _helogrp addWaypoint [_wpform,0]; _wpcnt = _wpcnt + 1; } foreach [_m1, _m2, _m3, _m4, _m5, _m6]; Regards, Scott Sent from my iPad using Tapatalk Share this post Link to post Share on other sites