ghandolhagen 11 Posted May 4, 2014 I have two arrays. One has 10 values in it, one is empty. I want to randomly select values from the first and place them into the second while at the same time removing them from the first to avoid duplication. Will this work or am I forgetting a parenthesis or something else? This is what I have so far: for "_i" from 1 to count _waypoints do{ _randIndex = _waypoints select floor count random _waypoints; _patrolPath set [count _patrolPath, _waypoints select _randIndex]; _waypoints resize _randIndex, 1; }; Thanks for taking a look :D Share this post Link to post Share on other sites
champ-1 40 Posted May 4, 2014 _randIndex = _waypoints select floor random count _waypoints; ---------- Post added at 16:03 ---------- Previous post was at 16:01 ---------- _randIndex has already selected waypoint in it. You don't need to select it later again. Share this post Link to post Share on other sites
ghandolhagen 11 Posted May 4, 2014 So just by using _waypoints select floor, that is giving me a random index within _waypoints? _random index should be a different value every time the loop iterates until there are no more way points left to randomly select and move. Share this post Link to post Share on other sites
champ-1 40 Posted May 4, 2014 (edited) Ok, I will just write it from scratch: _array1 = []; _array2 = []; _some_time = 300; for "_i" from 0 to 9 do { _thing = _array1 select random (floor (count _array1 + 1)); _array2 set [count _array2,_thing]; _array1 = _array1 - _thing; sleep _some_time; }; EDITED Edited May 4, 2014 by Champ-1 Share this post Link to post Share on other sites
ghandolhagen 11 Posted May 4, 2014 Hmm. cool. I'll incorporate some of these ideas and give it a try. Thanks for your time. :D Share this post Link to post Share on other sites
champ-1 40 Posted May 4, 2014 Notice that I edited it a bit after posting. Share this post Link to post Share on other sites
ghandolhagen 11 Posted May 4, 2014 (edited) No worries. In javascript I would write it like this: <script> var waypoints = ["wp1", "wp2", "wp3", "wp4", "wp5", "wp6", "wp7", "wp8", "wp9", "wp10"]; var patrolPath = []; for(var i=0; i<waypoints.length; i=i){ var randIndex = Math.floor(Math.random()*waypoints.length); patrolPath.push(waypoints[randIndex]); waypoints.splice(randIndex, 1); } console.log("Patrol Path: " + patrolPath); </script> The syntax of arma confuses the hell out of me... I should also clarify that the first array will actually have n elements in it not just 10.... Edited May 4, 2014 by ghandolhagen clarification Share this post Link to post Share on other sites
champ-1 40 Posted May 4, 2014 In that case: for "_i" from 0 to (count _array1 + 1) do { Share this post Link to post Share on other sites
ghandolhagen 11 Posted May 4, 2014 Ahhh thanks very much! And thanks for your time. :D Share this post Link to post Share on other sites
ghandolhagen 11 Posted May 5, 2014 Hello again everybody. I am updating this post to show my progress. I am currently stuck on a logic problem, but the rest of the code seems to work. What happens now is the unit moves to the first way point in the _patrolPath array but then stops, instead of continuing to the next one and so on... The logic that I am going for is If the unit isn't moving, then move to the current waypoint else wait until unit stops moving to move to the next waypoint. I can feel I am getting close there is just a problem with my logic that I am not seeing. Maybe a fresh pair of eyes would help? Here is the CODE: private ["_waypoints", "_patrolPath", "_randIndex", "_this", "_currentWP", "_isNotMoving", "_currentIndex"]; _waypoints = ["wp1", "wp2", "wp3", "wp4", "wp5", "wp6", "wp7", "wp8", "wp9", "wp10"]; _patrolPath = []; _currentWP; _isNotMoving = true; _currentIndex = 0; if((speed (vehicle _this)) == 0) then { _isNotMoving = true; }else{ _isNotMoving = false; }; for "_i" from 1 to (count _waypoints + 1) do{ _randIndex = _waypoints select random (floor count _waypoints); _patrolPath set [count _patrolPath, _randIndex]; _waypoints = _waypoints - _randIndex; }; _currentWp = _patrolPath select _currentIndex; for "_i" from 1 to (count _patrolPath + 1) do{ if(_isNotMoving) then { _this doMove (getMarkerPos _currentWP); _isNotMoving = false; }else{ waitUntil{_isNotMoving}; }; _currentIndex = _currentIndex + 1; _currentWP = _patrolPath select _currentIndex; }; Thanks again for taking a look :D Share this post Link to post Share on other sites
k0rd 3 Posted May 5, 2014 It seems like you are making this more complicated than it needs to be. You don't have to wait for a waypoint to finish before you assign another one, they can stack. _waypoints = ["wp1", "wp2", "wp3", "wp4", "wp5", "wp6", "wp7", "wp8", "wp9", "wp10"]; for "_i" from 1 to (count _waypoints + 1) do{ _randWP = _waypoints call BIS_fnc_selectRandom; (group _this) addWaypoint [_randWP, 0]; comment "substitute group _this for any group"; _waypoints= _waypoints - _randWP; }; Share this post Link to post Share on other sites
f2k sel 164 Posted May 5, 2014 (edited) Ghandolhagen you should have seen some errors from your code, if you didn't then you really need to enable -showscripterrors http://forums.bistudio.com/showthread.php?121163-Script-not-working-Use-the-showScriptErrors-parameter! I also couldn't get the above to work without some errors, working now. _waypoints = ["wp1", "wp2", "wp3", "wp4", "wp5", "wp6", "wp7", "wp8", "wp9", "wp10"]; for "_i" from 1 to (count _waypoints) do{ _randWP = _waypoints call BIS_fnc_selectRandom; (group _this) addWaypoint [getmarkerpos _randWP, 0]; comment "substitute group _this for any group"; _waypoints =_waypoints- [_randWP]; }; Edited May 5, 2014 by F2k Sel Share this post Link to post Share on other sites
ghandolhagen 11 Posted May 5, 2014 Wow yeah seems like I was trying to code that from scratch. Nice to know about the built in functions. Thanks for the heads up. I am trying to get a handle on the syntax. I am not used to it :P And I will look into the show script errors thing. Thanks a bunch k0rd and F2K Sel Share this post Link to post Share on other sites
k0rd 3 Posted May 5, 2014 thanks for correcting that f2k sel - i kind of just typed it up on the spot. ---------- Post added at 22:51 ---------- Previous post was at 22:49 ---------- Wow yeah seems like I was trying to code that from scratch. Nice to know about the built in functions. Thanks for the heads up. I am trying to get a handle on the syntax. I am not used to it :P And I will look into the show script errors thing. Thanks a bunch k0rd and F2K Sel there are a lot of helpful BIS_fnc functions :) Share this post Link to post Share on other sites
ghandolhagen 11 Posted May 5, 2014 Just a quick follow up. I tried the code and the group moves to a random waypoint (the first one) just fine, however they stop when they get there they don't move to the next in the series. I appreciate the feedback and the code snippets. A lot less intimidating to work with than my madness :D I'll keep crunching on it and post an update if I get a breakthough. Cheers! Share this post Link to post Share on other sites
k0rd 3 Posted May 5, 2014 Just a quick follow up. I tried the code and the group moves to a random waypoint (the first one) just fine, however they stop when they get there they don't move to the next in the series. I appreciate the feedback and the code snippets. A lot less intimidating to work with than my madness :D I'll keep crunching on it and post an update if I get a breakthough. Cheers! try adding a setWaypointType in there like _waypoints = ["wp1", "wp2", "wp3", "wp4", "wp5", "wp6", "wp7", "wp8", "wp9", "wp10"]; for "_i" from 1 to (count _waypoints) do{ _randWP = _waypoints call BIS_fnc_selectRandom; _thiswp=(group _this) addWaypoint [getmarkerpos _randWP, 0]; _thiswp setWaypointType "SAD"; _waypoints =_waypoints- [_randWP]; }; Share this post Link to post Share on other sites
ghandolhagen 11 Posted May 5, 2014 try adding a setWaypointType in there like _waypoints = ["wp1", "wp2", "wp3", "wp4", "wp5", "wp6", "wp7", "wp8", "wp9", "wp10"]; for "_i" from 1 to (count _waypoints) do{ _randWP = _waypoints call BIS_fnc_selectRandom; _thiswp=(group _this) addWaypoint [getmarkerpos _randWP, 0]; _thiswp setWaypointType "SAD"; _waypoints =_waypoints- [_randWP]; }; Thanks for the suggestion, unfortunately, setting a search and destroy waypoint only results in them wandering around the initial waypoint until they have determined it is clear then they stop moving. Ignoring all the other waypoints in the chain . This is a tricky one but i do appreciate all the feedback and support. Cheers :D Share this post Link to post Share on other sites
champ-1 40 Posted May 5, 2014 I guess you just overwriting 0-waypoint over and over again. Try it like this: _thiswp = (group _this) addWaypoint [getmarkerpos _randWP, _i]; or this _thiswp = (group _this) addWaypoint [getmarkerpos _randWP, 0, _i]; Share this post Link to post Share on other sites
ghandolhagen 11 Posted May 6, 2014 Hey Champ-1, thanks for chiming in again. Still no dice. they just stand still and don't move at all. In my original script (the one where I was trying to write the whole thing from scratch) The logic I was following was, 1. randomize waypoints 2. store random wps in an array 3. Conditional to see if the units were moving or not. If yes then continue to current way point , if not then go to the next wp in the array via something like a currentIndex variable or something unless they were at the end of the wp chain.... Share this post Link to post Share on other sites
f2k sel 164 Posted May 6, 2014 (edited) Try changing the setwaypointtype from "SAD"; to "MOVE"; Also if your using the Dev version waypoints are in a bit of a mess right now and don't always work. Edited May 6, 2014 by F2k Sel Share this post Link to post Share on other sites
ghandolhagen 11 Posted May 6, 2014 (edited) Try changing the setwaypointtype from "SAD"; to "MOVE";Also if your using the Dev version waypoints are in a bit of a mess right now and don't always work. good to know :P I will check it out. also for the sake of thoroughness here is an example conditional I was playing with but it doesn't work either: if((speed _this == 0) && (_this distance _currentWP < 5)) then{ _currentIndex = _currentIndex +1; _nextWP = _patrolPath select _currentIndex; _currentWP = _nextWP; {_x doMove getMarkerPos _currentWP} forEach units group _this; }; Edited May 6, 2014 by ghandolhagen conditional example Share this post Link to post Share on other sites
.kju 3240 Posted May 6, 2014 get Squint from SBS Mac - it does static code analysis Share this post Link to post Share on other sites
ghandolhagen 11 Posted May 6, 2014 Thanks for the tip .kju Share this post Link to post Share on other sites