twisted 128 Posted February 24, 2016 So I'm trying to do what should be quite simple. get a list of houses. then go through the list - adding a house to a separate final list then remove it and all houses within 200m from it from the original list. and do this for each units of what should be an ever shrinking list. _tws_near_buildings = _temp_x_pos nearObjects ["House", 2000]; tws_final_house_list = []; { uisleep 0.01; _here = getpos _x; _tws_near_buildings2 = _here nearObjects ["House", 200]; tws_final_house_list pushBack _x; _tws_near_buildings = _tws_near_buildings - [_tws_near_buildings2]; }; } foreach _tws_near_buildings; but nothing ever gets removed. Im no doubt being dense. Share this post Link to post Share on other sites
Joe98 92 Posted February 24, 2016 Maybe each building has a separate name and you need to refer to the name? Share this post Link to post Share on other sites
davidoss 552 Posted February 24, 2016 _tws_near_building ==>_tws_near_buildings _tws_places ? [?] 1 Share this post Link to post Share on other sites
twisted 128 Posted February 24, 2016 _tws_near_building ==>_tws_near_buildings _tws_places ? [?] i stuffed up the copy and paste. fixed. basically i'm trying to go through the list and shorten it while going through it Share this post Link to post Share on other sites
ProfTournesol 956 Posted February 24, 2016 How do you know it doesn't work as intended ? Share this post Link to post Share on other sites
twisted 128 Posted February 24, 2016 How do you know it doesn't work as intended ? Good question. Because i get the code to draw dots on the houses chosen and then different color dots on the houses that should be at least 140m away. but all the dots get the color. rather than stuff around with the copy pasted truncated code above here is the testing code i use. _temp_x_pos = getpos player; _tws_near_buildings = _temp_x_pos nearObjects ["House", 4000]; _tws_building_types = []; _tws_buildings_sorted = [ "Land_MilOffices_V1_F", "Land_BagBunker_Large_F", "Land_i_Barracks_V1_F", "Land_u_Barracks_V2_F", "Land_Cargo_House_V1_F", "Land_Cargo_House_V2_F", "Land_Cargo_House_V3_F", "Land_Cargo_HQ_V1_F", "Land_Cargo_HQ_V2_F", "Land_Cargo_HQ_V3_F", "Land_Cargo_Patrol_V1_F", "Land_Cargo_Patrol_V2_F", "Land_Cargo_Patrol_V3_F", "Land_Cargo_Tower_V1_F", "Land_Cargo_Tower_V1_No1_F", "Land_Cargo_Tower_V1_No2_F", "Land_Cargo_Tower_V1_No3_F", "Land_Cargo_Tower_V1_No4_F", "Land_Cargo_Tower_V1_No5_F", "Land_Cargo_Tower_V1_No6_F", "Land_Cargo_Tower_V1_No7_F", "Land_Cargo_Tower_V2_F", "Land_Cargo_Tower_V3_F", "Land_Medevac_house_V1_F", "Land_Medevac_HQ_V1_F", "Land_i_House_Big_01_V3_F", "Land_i_House_Small_01_V3_F", "Land_i_Stone_HouseBig_V2_F", "Land_i_Stone_HouseBig_V3_F", "Land_Unfinished_Building_01_F", "Land_Unfinished_Building_02_F", "Land_LightHouse_F", "Land_Castle_01_tower_F", "Land_Airport_center_F" ]; _cargoBs = []; _barrackBs = []; _milOfficeBs = []; _tws_places = []; { _tws_temp_x = _x; _toString = typeOf _tws_temp_x; diag_log format ["in setup ofpor space TYPEOF is %1", _tws_temp_x]; diag_log format ["in setup ofpor space %1", _toString]; systemChat format ["in setup ofpor space%1", _x]; systemChat format ["in setup ofpor space%1", _toString]; _tws_found = _toString in _tws_buildings_sorted; systemChat format ["_tws_found %1 for %2", _tws_found,_tws_temp_x]; diag_log format ["_tws_found %1 for %2", _tws_found,_tws_temp_x]; if (_tws_found) then { _cargoBs pushBack _x; diag_log format ["in setup opfor space looking at buildign - %1", _tws_temp_x]; _chance = random 10; if (_chance > 3) then { _tws_positions = [_x] call BIS_fnc_buildingPositions; _tws_pos_max = (count _tws_positions) ; systemChat format ["in setup opfor space looking at buildign - %1 whihc has %2 posiitons ", _tws_temp_x, _tws_pos_max]; diag_log format ["in setup opfor space looking at buildign - %1 whihc has %2 posiitons ", _tws_temp_x, _tws_pos_max]; if (_tws_pos_max > 0) then { /*_tempGroup = createGroup east;*/ _tws_picked_Pos = floor random _tws_pos_max ; systemChat format ["in setup opfor space picking posiiton at ", _tws_picked_Pos]; diag_log format ["in setup opfor space picking posiiton at ", _tws_picked_Pos]; _newPos = _tws_temp_x buildingPos _tws_picked_Pos; systemChat format ["in setup opfor space picking which has a pos at ", _newPos]; diag_log format ["in setup opfor space picking which has a pos at ", _newPos]; _newMarker = floor random 10000; _markerName2 = format ["tws_AI_here_%1_%2",_tws_temp_x,_newMarker]; _markerstr2 = createMarker [_markerName2,_newPos]; _markerstr2 setMarkerShape "ICON"; _markerstr2 setMarkerColor "ColorGreen"; _markerstr2 setMarkerType "mil_dot"; _tws_places pushBack _x; _newPos set [2, (_newPos select 2) + 6]; _veh = createVehicle ["Sign_Sphere100cm_F", _newPos, [], 0, "none"]; _veh setObjectTexture [0,'#(argb,8,8,3)color(0.55,0,0.1,1)']; }; }; }; uisleep 0.01; } foreach _tws_near_buildings; /////////// now check that no buildings are 150m close to each other tws_final_house_list = []; { uisleep 0.01; _here = getpos _x; _newMarker = floor random 10000; _markerName2 = format ["here_%1_%2",_here,_newMarker]; _markerstr2 = createMarker [_markerName2,_here]; _markerstr2 setMarkerShape "ICON"; _markerstr2 setMarkerColor "ColorBlack"; _markerstr2 setMarkerType "mil_dot"; _tws_near_buildings2 = _here nearObjects ["House", 149]; _here set [2,10]; _veh = createVehicle ["Sign_Sphere100cm_F", _here, [], 0, "none"]; _veh setObjectTexture [0,'#(argb,8,8,3)color(0.55,0,0.56,1)']; tws_final_house_list pushBack _x; systemChat format ["_x at twsplaces is %1", _x]; diag_log format ["counting _tws_places %1", count _tws_places]; systemChat format ["counting _tws_places %1", count _tws_places]; diag_log format ["_tws_near_buildings2 %1", _tws_near_buildings2]; systemChat format ["_tws_near_buildings2 %1", _tws_near_buildings2]; _tws_places = _tws_places - [_tws_near_buildings2]; } foreach _tws_places; diag_log format ["_tws_places are %1", _tws_places]; _max_groups = 12; _total_groups = []; { _chance = random 10; if (_chance > 5) then { _newPos = getpos _x; _newMarker = floor random 10000; _markerName2 = format ["tws_AI_here2_%1_%2",_newPos,_newMarker]; _markerstr2 = createMarker [_markerName2,_newPos]; _markerstr2 setMarkerShape "ICON"; _markerstr2 setMarkerColor "ColorYellow"; _markerstr2 setMarkerType "mil_dot"; _newPos set [2, (_newPos select 2) + 8]; _veh = createVehicle ["Sign_Sphere100cm_F", _newPos, [], 0, "none"]; _veh setObjectTexture [0,'#(argb,8,8,3)color(0.55,0.55,0.1,1)']; uisleep 0.01; }; } foreach tws_final_house_list; publicVariable "tws_final_house_list"; save it as something.sqf run it eden editor. place a unit. then press esc and type [] execvm "something.sqf" in the code box thingy. you'll see that it doesnt work. Share this post Link to post Share on other sites
twisted 128 Posted February 24, 2016 ok, so i tried some other code and at least the house list gets lower. seems that you cant change the length of an array you are foreaching through - arma 3 will keep the orginal one in memory if I'm correct. using a while loop works, but it still doesn't delete all houses within 150m of the one house. i cant figure out why. edit - it was me being dense. I was putting brackets around the nearObjects array and then subtracting the array within an array which of course didnt find any match. _tws_near_buildings2 = _here nearObjects ["House", 200];_tws_places = _tws_places - [_tws_near_buildings2]; _temp_x_pos = getpos player; _tws_near_buildings = _temp_x_pos nearObjects ["House", 4000]; _tws_building_types = []; _tws_buildings_sorted = [ "Land_MilOffices_V1_F", "Land_BagBunker_Large_F", "Land_i_Barracks_V1_F", "Land_u_Barracks_V2_F", "Land_Cargo_House_V1_F", "Land_Cargo_House_V2_F", "Land_Cargo_House_V3_F", "Land_Cargo_HQ_V1_F", "Land_Cargo_HQ_V2_F", "Land_Cargo_HQ_V3_F", "Land_Cargo_Patrol_V1_F", "Land_Cargo_Patrol_V2_F", "Land_Cargo_Patrol_V3_F", "Land_Cargo_Tower_V1_F", "Land_Cargo_Tower_V1_No1_F", "Land_Cargo_Tower_V1_No2_F", "Land_Cargo_Tower_V1_No3_F", "Land_Cargo_Tower_V1_No4_F", "Land_Cargo_Tower_V1_No5_F", "Land_Cargo_Tower_V1_No6_F", "Land_Cargo_Tower_V1_No7_F", "Land_Cargo_Tower_V2_F", "Land_Cargo_Tower_V3_F", "Land_Medevac_house_V1_F", "Land_Medevac_HQ_V1_F", "Land_i_House_Big_01_V3_F", "Land_i_House_Small_01_V3_F", "Land_i_Stone_HouseBig_V2_F", "Land_i_Stone_HouseBig_V3_F", "Land_Unfinished_Building_01_F", "Land_Unfinished_Building_02_F", "Land_LightHouse_F", "Land_Castle_01_tower_F", "Land_Airport_center_F" ]; _cargoBs = []; _barrackBs = []; _milOfficeBs = []; _tws_places = []; { _tws_temp_x = _x; _toString = typeOf _tws_temp_x; diag_log format ["in setup ofpor space TYPEOF is %1", _tws_temp_x]; diag_log format ["in setup ofpor space %1", _toString]; systemChat format ["in setup ofpor space%1", _x]; systemChat format ["in setup ofpor space%1", _toString]; _tws_found = _toString in _tws_buildings_sorted; systemChat format ["_tws_found %1 for %2", _tws_found,_tws_temp_x]; diag_log format ["_tws_found %1 for %2", _tws_found,_tws_temp_x]; if (_tws_found) then { _cargoBs pushBack _x; diag_log format ["in setup opfor space looking at buildign - %1", _tws_temp_x]; _chance = random 10; if (_chance > 3) then { _tws_positions = [_x] call BIS_fnc_buildingPositions; _tws_pos_max = (count _tws_positions) ; systemChat format ["in setup opfor space looking at buildign - %1 whihc has %2 posiitons ", _tws_temp_x, _tws_pos_max]; diag_log format ["in setup opfor space looking at buildign - %1 whihc has %2 posiitons ", _tws_temp_x, _tws_pos_max]; if (_tws_pos_max > 0) then { /*_tempGroup = createGroup east;*/ _tws_picked_Pos = floor random _tws_pos_max ; systemChat format ["in setup opfor space picking posiiton at ", _tws_picked_Pos]; diag_log format ["in setup opfor space picking posiiton at ", _tws_picked_Pos]; _newPos = _tws_temp_x buildingPos _tws_picked_Pos; systemChat format ["in setup opfor space picking which has a pos at ", _newPos]; diag_log format ["in setup opfor space picking which has a pos at ", _newPos]; _newMarker = floor random 10000; _markerName2 = format ["tws_AI_here_%1_%2",_tws_temp_x,_newMarker]; _markerstr2 = createMarker [_markerName2,_newPos]; _markerstr2 setMarkerShape "ICON"; _markerstr2 setMarkerColor "ColorGreen"; _markerstr2 setMarkerType "mil_dot"; _tws_places pushBack _x; _newPos set [2, (_newPos select 2) + 6]; _veh = createVehicle ["Sign_Sphere100cm_F", _newPos, [], 0, "none"]; _veh setObjectTexture [0,'#(argb,8,8,3)color(0.55,0,0.1,1)']; }; }; }; uisleep 0.01; } foreach _tws_near_buildings; /////////// now check that no buildings are 150m close to each other tws_final_house_list = []; _recurse = 1; _counter = 0; while {_recurse == 1} do { uisleep 0.1; if (count _tws_places <1) exitWith { uisleep 0.01; diag_log format ["tws_palces is now empty %1", _tws_places]; }; _picked = floor random count _tws_places; _chosen = _tws_places select _picked; _here = getpos _chosen; _here set [2,10]; _veh = createVehicle ["Sign_Sphere100cm_F", _here, [], 0, "none"]; _veh setObjectTexture [0,'#(argb,8,8,3)color(0.55,0.1,0.76,1)']; _newPos = _here; _newMarker = floor random 17000; _markerName2 = format ["twss_AI_here2_%1_%2",_newPos,_newMarker]; _markerstr2 = createMarker [_markerName2,_newPos]; _markerstr2 setMarkerShape "ICON"; _markerstr2 setMarkerColor "ColorRed"; _markerstr2 setMarkerType "mil_dot"; tws_final_house_list pushBack _chosen; _tws_places deleteAt _picked; _tws_near_buildings2 = _here nearObjects ["House", 200]; _tws_places = _tws_places - [_tws_near_buildings2]; diag_log format ["_tws_places count is %1",count _tws_places]; systemChat format ["_tws_places count is %1", count _tws_places]; }; diag_log format ["_tws_places are %1", _tws_places]; Share this post Link to post Share on other sites