Jump to content
Sign in to follow this  
anaximandross

Indexing through array is returning a string instead of value

Recommended Posts

I've got a script running pretty well, except for the very end of it. I'm passing an array, _markerLocationArray into the end of this function, and when I go to get the positions of each of the markers in the array, I get an error stating that a string is being returned instead of a position.  To be specific, its the last ten lines or so that are throwing the error. The line_position = getMarkerPos _x is the error line. Thanks in advance!

 

 

if(!isServer) exitWith{}; 

//params ["_marker", "_foodCost"];
if(!isServer) exitWith{}; 


//add a new parameter for array of markers being passed into createBasePlots

(_this select 3) params ["_marker","_foodCost","_markerLocationArray"];
base_num = (_this select 3) select 2;
_markerLocationArray = (_this select 3) select 3;
//Counts number of enemies around the desired marker
_units = [];
{if (side _x == east && {_marker distance2D _x < 100}) then {_units pushBack _x};} forEach allUnits;

_cnt = count _units;

sleep 0.5;

_globalFood = GLOBALFOOD;


//checks to see if the area around the base is clear
if(_cnt > 0) then { 
	hint "Clear the area to claim this base!"
	}

//if the area is clear, this allows the player to claim the base
else{ 
	if(_globalFood > _foodCost) then {

			_markPos = getMarkerPos "base_4"; 
			//calculates the amount of food remaining in food stores
			_foodremaining = _globalfood - _foodCost; 
			
			GLOBALFOOD = _foodremaining; 
			publicVariable "GLOBALFOOD"; 
			//hint format["You have %1 food remaining!",_foodremaining];

			//determines the current base number to be used for other things
			CURRENTBASENUMBER = base_num; 
			publicVariable "CURRENTBASENUMBER"; 

			//creates a marker at the current base. This is used for AI targetting 
			deleteMarker "CurrentBase"; 
			deleteMarker "base_4";
			_currentBaseMarker = createMarker["CurrentBase", _markPos]; 
			"CurrentBase" setMarkerColor "ColorBlue";
			"CurrentBase" setMarkerText "Home Base"; 
			"CurrentBase" setMarkerType "mil_circle";

			//call function to create all marker plots at the new base
			//0 = ["_markerLocationArray"] execVM "BaseFunctions\CreateBasePlots.sqf";

			
			_cont = count _markerLocationArray; 
			hint format ["Count %1",_cont];
			{
				//gets position of current array value
				_position = getMarkerPos _x;

				//builds yellow square on current array position
				_veh = "VR_Area_01_4x4_yellow_F" createVehicle _position;

				//Adds 4 actions to each item to allow various things to be built
				_veh addAction ["Build a Small Farm", "Compositions\assembler.sqf",[_position, "foodS"]];
				_veh addAction ["Build a Large Farm", "Compositions\assembler.sqf",[_position, "foodL"]];
				_veh addAction ["Build a Small Workshop", "Compositions\assembler.sqf",[_position, "workshopS"]];
				_veh addAction ["Build a Large Workshop", "Compositions\assembler.sqf",[_position, "workshopL"]];
				_veh addAction ["Build a Storage Facility", "Compositions\assembler.sqf",[_position, "storage"]];

			} forEach _markerLocationArray;
	}
};

 

Share this post


Link to post
Share on other sites
1 hour ago, anaximandross said:

(_this select 3) params ["_marker","_foodCost","_markerLocationArray"];

base_num = (_this select 3) select 2;

_markerLocationArray = (_this select 3) select 3;

 

1. Redo this quoted part, it doesn't make sense. First you read the variables using params then you overwrite them using select but in a different configuration. Stick with 1 method (params is best IMHO) and make sure it retrieves the correct parameters.

 

2. Protect your variables! Don't just declare them. Use private. 

 

3. Check your arguments so you are actually passing what is expected. 

 

Also in the future when posting errors paste the actual error from the .rpt file as well as your description of it. It helps.

  • Like 1

Share this post


Link to post
Share on other sites

I actually got some help with that part here on the forums (its on my last post). The _MarkerArrayList is being passed as the 4th param from the script caller, but it wasn't taking the right inputs. To be honest, I really, really struggled with this part of the script, and I don't know how to make it work properly. This is my first major project that I've undertaken. I don't have access to my .rpt at the moment, but I will post it later. 

Share this post


Link to post
Share on other sites
16 hours ago, mrcurry said:

 

1. Redo this quoted part, it doesn't make sense. First you read the variables using params then you overwrite them using select but in a different configuration. Stick with 1 method (params is best IMHO) and make sure it retrieves the correct parameters.

 

2. Protect your variables! Don't just declare them. Use private. 

 

3. Check your arguments so you are actually passing what is expected. 

 

Also in the future when posting errors paste the actual error from the .rpt file as well as your description of it. It helps.

Ok! So i've cleaned up that first segment of code, I think it was added in for debugging, but it works fine (at least that part of it). I've checked that all of my params are being passed correctly, and they are. The last issue I'm getting is that my array is not the correct type. Here is my code:

Spoiler

if(!isServer) exitWith{}; 

//params ["_marker", "_foodCost"];
if(!isServer) exitWith{}; 


//add a new parameter for array of markers being passed into createBasePlots

(_this select 3) params ["_marker","_foodCost","_baseNum","_markerLocationArray"];

//Counts number of enemies around the desired marker
_units = [];
{if (side _x == east && {_marker distance2D _x < 100}) then {_units pushBack _x};} forEach allUnits;

_cnt = count _units;

sleep 0.5;

_globalFood = GLOBALFOOD;


//checks to see if the area around the base is clear
if(_cnt > 0) then { 
	hint "Clear the area to claim this base!"
	}

//if the area is clear, this allows the player to claim the base
else{ 
	if(_globalFood > _foodCost) then {

			_markPos = getMarkerPos "base_4"; 
			//calculates the amount of food remaining in food stores
			_foodremaining = _globalfood - _foodCost; 
			
			GLOBALFOOD = _foodremaining; 
			publicVariable "GLOBALFOOD"; 
			//hint format["You have %1 food remaining!",_foodremaining];

			//determines the current base number to be used for other things
			CURRENTBASENUMBER = _baseNum; 
			publicVariable "CURRENTBASENUMBER"; 
			//hint format ["Current Base %1",CURRENTBASENUMBER];

			//creates a marker at the current base. This is used for AI targetting 
			deleteMarker "CurrentBase"; 
			deleteMarker "base_4";
			_currentBaseMarker = createMarker["CurrentBase", _markPos]; 
			"CurrentBase" setMarkerColor "ColorBlue";
			"CurrentBase" setMarkerText "Home Base"; 
			"CurrentBase" setMarkerType "mil_circle";

			//call function to create all marker plots at the new base
			//0 = ["_markerLocationArray"] execVM "BaseFunctions\CreateBasePlots.sqf";

			
			_cont = count _markerLocationArray; 
			hint format ["Count %1",_cont];
			{
				//gets position of current array value
				_position = getMarkerPos _x;

				//builds yellow square on current array position
				_veh = "VR_Area_01_4x4_yellow_F" createVehicle _position;

				//Adds 4 actions to each item to allow various things to be built
				_veh addAction ["Build a Small Farm", "Compositions\assembler.sqf",[_position, "foodS"]];
				_veh addAction ["Build a Large Farm", "Compositions\assembler.sqf",[_position, "foodL"]];
				_veh addAction ["Build a Small Workshop", "Compositions\assembler.sqf",[_position, "workshopS"]];
				_veh addAction ["Build a Large Workshop", "Compositions\assembler.sqf",[_position, "workshopL"]];
				_veh addAction ["Build a Storage Facility", "Compositions\assembler.sqf",[_position, "storage"]];

			} forEach _markerLocationArray;
	}
};

 

 

The only issue I'm getting now is on the final portion of the script. It's not throwing any errors, and I've got it building the VR squares, the only issue I'm having now is coming up with a solution to passing the position into the assembler function, but I'm sure I can figure that out!

  • Like 1

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  

×