Jump to content
Sign in to follow this  
bigshotking

nearestLocations not yielding results

Recommended Posts

I've created this script to find locations around the map of Takistan, but the script seems to stop after the debug message "STARTING". I've waited up to ten minutes and the other debug message "FINISHED" never pops up.

Is there some sort of error that I'm currently missing in this? I call it from a server init like this:

null = execVM "server\mission_loop.sqf"; 

Here is the script:

loc_towns = [];
loc_hills = [];
loc_airports = [];
loc_viewpoints = [];
loc_passes = [];

_loc = nearestLocations [[0,0,0],["Name","NameLocal","NameVillage","NameCity","NameCityCapital","Hill","Airport","ViewPoint"],50000];

player sideChat "STARTING";

{	
if( position _x distance getMarkerPos "fob" > 1500) then {
	switch (type _x) do {
		case "Name": {loc_passes = loc_passes + [_x];};
		case "NameLocal": {loc_passes = loc_passes + [_x];};
		case "NameVillage": {loc_towns = loc_towns + [_x];};
		case "NameCity": {loc_towns = loc_towns + [_x];};
		case "NameCityCapital": {loc_towns = loc_towns + [_x];};
		case "Hill": {loc_hills = loc_hills + [_x];};
		case "Airport": {loc_airports = loc_airports + [_x];};
		case "ViewPoint": {loc_viewpoints = loc_viewpoints + [_x];};
	};
} foreach _loc;

player sideChat "FINISHED";

I have a COMP spawning script that uses some of these locations, but nothing happens, I would assume that it insures that the mission_loop.sqf is at fault.

Thanks for any help,

-Bigshot

Share this post


Link to post
Share on other sites

don't forget to close the if structure

{    
   if( position _x distance getMarkerPos "fob" > 1500) then {
       switch (type _x) do {
           case "Name": {loc_passes = loc_passes + [_x];};
           case "NameLocal": {loc_passes = loc_passes + [_x];};
           case "NameVillage": {loc_towns = loc_towns + [_x];};
           case "NameCity": {loc_towns = loc_towns + [_x];};
           case "NameCityCapital": {loc_towns = loc_towns + [_x];};
           case "Hill": {loc_hills = loc_hills + [_x];};
           case "Airport": {loc_airports = loc_airports + [_x];};
           case "ViewPoint": {loc_viewpoints = loc_viewpoints + [_x];};
       };
   [color="#FF0000"]};[/color]
} foreach _loc;

Share this post


Link to post
Share on other sites

Also, because the script will be itterating through many, many locations and indexing the whole map - you might want to consider some optimizations.

Specifically, you could situate the command between startLoadingScreen ... and endLoadingScreen so that the engine is dedicated to running the scripts and does not do any simulation processing or rendering.

A good page to read is Code Optimization on the wiki.

- Binary array addition is significantly slower than using set:

loc_passes set [count loc_passes,_x]

- Position is much slower that getPosATL or getPosASL.

Furthermore, if you want ALL the locations on the map, it might be far more practical and cost much less performance to read the locations from the config file directly, rather than use nearestLocations as this has to search the map for them. In fact, depending on what you are doing with the values, you could possibly read them directly from the config without having to store them as an array. The config is already loaded memory anyway, so it's there to use for "free".

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  

×