Jump to content
Sign in to follow this  
mantls

Help with Loops in Loops

Recommended Posts

Hey,

I'm trying to put all MapGrids which have Houses inside into an Array in order to acces them.

So i figured i'll just check each Grid for Houses, however my Loop seems to be stuck at it's first iteration (one Marker at [50,50,0] is being created).

Frankly neither me nor Squint2 are able to spot any Errors.

GridMapper_fnc = 
{
if (!isServer) exitWith {};
private ["_GridsArray","_checkPos","_checkArr","_xPos","_n","_mrk","_yPos","_xMax","_yMax","_count"];
_xMax = 30000 / 100;
_yMax = 27000 / 100;
_xPos = 50;
_yPos = 50;

_GridsArray = [];

_count = 0; // Debug Marker

for "_i" from 1 to _yMax do
{
 _xPos = 50;

 for "_g" from 1 to _xMax do
 {
  _checkPos = [_xPos,_yPos,0];
  _checkArr = nearestObjects [_checkPos, ["House"], 50];
  if (count _checkArr > 0) then {_GridsArray = _GridsArray + [_checkPos];};

  _xPos = _xPos + 100; // move up 1 xGrid

  _n = format ["mrk_%1", _count]; _count + 1; // Debug Marker
  _mrk = createMarker [_n, _checkPos]; // Debug Marker
  _mrk setMarkerType "Mil_Dot"; // Debug Marker

 };

 _yPos = _yPos + 100; // move up 1 yGrid
};


hint format ["%1 || %2", _xMax, _yMax]; // Debug 

};

Thank you very much :)

Share this post


Link to post
Share on other sites

hi mantls,

while i experimented with div ways to spawn loot on Altis, i tried that approach too.

the functioning part of code is this:

//find building on map
	_tmpBuildName set [0, _x];
	_buildingname = _x;
	diag_log format["-- LOOTSPAWNER DEBUG trace building: %1, %2 --", _tmpBuildName, _buildingname];
	_buildingfound = false;
	_building_list = [];
	_xused = xMin;
	while {((_xused < xMax) || (!_buildingfound))} do {
		_yused = yMin;
		while {((_yused < yMax) || (!_buildingfound))} do {
			_posArea = [_xused, _yused, 0];
			_building_list = nearestObjects [_posArea, _tmpBuildName, _areaRad];
			if ((count _building_list) != 0) then {
				_buildingfound = true;
			};
			_yused = _yused + _SaDist;
			//sleep 0.001;
		};
		_xused = _xused + _SaDist;
		//sleep 0.001;
	};

hope it helps

Share this post


Link to post
Share on other sites

_count = _count +1;

line 26 of your code. It's never updated.

Edit: Other than that, seems to work. You might want to use set instead of that array addition, though

Share this post


Link to post
Share on other sites

jeeeeeeeeeeeez, late night scripting.... :D

Thanks for the Heads up, i had that feeling it was something fishy...

Takes awful long so i guess ill have to run it once and save the Array but eh.

Thank you :D

Share this post


Link to post
Share on other sites

Was playing with your code thought id post it back up with some changes.

Changed it a little to use A3 config so it works for any map

Used the step function of for loops to iterate position.

Included a copy to clipboard option to output _GridArrays.

Included debug boolean for whether or not to create markers.

Made checkable grid size a function option.

GridMapper_fnc = {
if (!isServer) exitWith {};
_worldSize = getNumber (configFile >> "CFGWorlds" >> worldName >> "mapsize");
_GridSize = [_this, 0, 100, [0]] call BIS_fnc_param;
_GridOffset = _GridSize / 2;
_GridsArray = [];
_copy = [_this, 1, false, [true]] call BIS_fnc_param;
_debug = [_this, 2, false, [true]] call BIS_fnc_param;
_mrk = objNull;

for "_x" from 0 to _worldSize step _GridSize do {

	for "_y" from 0 to _worldSize step _GridSize do {

		if (_debug) then {
			_markerName = format ["buildingGrid_%1_%2", _x, _y];
			_mrk = createMarker [_markerName, [_x + _GridOffset, _y + _GridOffset, 0]];
			_mrk setMarkerShape "rectangle";
			_mrk setMarkerSize [_GridOffset *0.75, _GridOffset *0.75];
		};

		_checkPos = [_x + _GridOffset, _y + _GridOffset, 0];
		_checkArr = nearestObjects [_checkPos, ["House"], _GridOffset];
		if (count _checkArr > 0) then {
			_GridsArray = _GridsArray + [_checkPos];
			if (_debug) then { _mrk setMarkerColor "colorGreen"; };
		}else{
			if (_debug) then { _mrk setMarkerColor "colorRed"; };
		};
	};
};
if ( _copy ) then {
	copyToClipboard (str _GridsArray);
	hint format ["Array holds %1 areas", count _GridsArray];
};
};

h = [100, true, true] spawn GridMapper_fnc;

Edited by Larrow

Share this post


Link to post
Share on other sites

Oh, cool! That'll be very neat for future Maps.

How long does this one take? My first attempt took like 15 minutes (hell, maybe even 20) so i just went through the whole Map once and then copied the array to a textFile so that i'll never need to do that again :D.

Share this post


Link to post
Share on other sites

Will take the same amount of time as its still using the same command to check for houses.

Could maybe experiment with this maybe nearentities is faster? or as we only need to find one type of HOUSE to know about the area maybe check for an entity in a loop of ever expanding range till you get to the area size or find one and then exit. As we only need to know if there is a HOUSE within _GridSize of the position its a waste to get a list of all!!

Seems to be markers that take alot of time up,

Stratis takes 13 seconds with markers but .5 of a second without.

Altis takes #(didnt want to wait that long) seconds with markers but 84 seconds without.

I did notice a pattern though after letting Altis run for a while with markers, Electrical power lines are picked up by "HOUSE" adding alot of unneeded areas.

Edited by Larrow

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×