Jump to content
Sign in to follow this  
anaximandross

Type object expected array

Recommended Posts

I wrote a script that allows the user to access a terminal and spawn in a multitude of facility plots. Each of these plots is represented as a blue arrow which is hidden by default, and then deleted when the plot is spawned in. However, when I try to run this script, I'm getting an error now saying that the array I'm passing in is an object, not an array. Here is this init of the terminal: 

 

hideObjectGlobal this; _plotArray2 = [b2_p1,b2_p2,b2_p3,b2_p4,b2_p5, b2_p6,b2_p7,b2_p8,b2_p9,b2_p10]; this addAction["Place Facility Plots","BaseFunctions\CreateBasePlots.sqf",[_plotArray2,b2_term]];

And here is the script CreateBasePlots.sqf

 

if(!isServer) exitWith{}; 

params ["_markerLocationArray","_target"];

hint "Welcome to the baseplot maker";
	_target removeAction 0;

	{
		//gets position of current array value
		_position = getPos _x;

		//builds yellow square on current array position
		_veh = "VR_Area_01_square_4x4_yellow_F" createVehicle _position;
		_cut = "Land_ClutterCutter_large_F" createVehicle _position;
		_postPole = "Land_VergePost_01_F" createVehicle _position; 

		// //Adds 5 actions to each item to allow various things to be built
		// _postPole addAction ["Build a Small Farm (15 Scrap)", "Compositions\assembler.sqf",[_position, "foodS"]];
		// _postPole addAction ["Build a Large Farm (45 Scrap)", "Compositions\assembler.sqf",[_position, "foodL"]];
		// _postPole addAction ["Build a Small Workshop (25 Scrap)", "Compositions\assembler.sqf",[_position, "workshopS"]];
		// _postPole addAction ["Build a Large Workshop (45 Scrap)", "Compositions\assembler.sqf",[_position, "workshopL"]];
		// _postPole addAction ["Build a Storage Facility (100 Scrap)", "Compositions\assembler.sqf",[_position, "storage"]];

		_postPole addAction ["Build a Small Farm (15 Scrap)", {[_this,"foodS"] execVM "Utility\BoxScrapper.sqf"}];
		_postPole addAction ["Build a Large Farm (45 Scrap)", {[_this,"foodS"] execVM "Utility\BoxScrapper.sqf"}];
		_postPole addAction ["Build a Small Workshop (25 Scrap)",{[_this,"foodS"] execVM "Utility\BoxScrapper.sqf"}];
		_postPole addAction ["Build a Large Workshop (45 Scrap)", {[_this,"foodS"] execVM "Utility\BoxScrapper.sqf"}];
		_postPole addAction ["Build a Storage Facility (100 Scrap)", {[_this,"storage"] execVM "Utility\BoxScrapper.sqf"}];


		this addAction["Recycle Items",{_this execVM "Utility\BoxScrapper.sqf"}];

		deleteVehicle _x;

	} forEach _markerLocationArray;

Here is my .rpt section: 

 

Spoiler

14:19:15 Error in expression <xScrapper.sqf"}];

deleteVehicle _x;

} forEach _markerLocationArray;
>
14:19:15   Error position: <forEach _markerLocationArray;
>
14:19:15   Error foreach: Type Object, expected Array

 

 

I have the top half commented out because I am trying to solve another issue. This script is being used at 4 other locations, so I'm defining the plot locations at each base as the base number_plot number (in this case b2_p1, etc). The issue is that I need to get the location of the object calling the assembler script that spawns in the composition, and i'm sure of how to do this. I was going to try passing _this as a parameter, but I have no clue if that will work. If anyone has any suggestions on how to do this better, any suggestions are accepted!

 

Here is the assembler.sqf:

 

Spoiler

if(!isServer) exitWith {}; 

params ["_facilityPositon","_facilityType","_facilityCost"];

_storPosit = getPos  _this;

hint format ["%1",_storposit];

if(GLOBALSCRAP > _facilityCost)  then {

	if (_facilityType isEqualTo "foodS") then {
		0 = [_storposit, 360, call (compile (preprocessFileLineNumbers "Compositions\foodstor_s.sqf"))] call BIS_fnc_ObjectsMapper;

	};

	if (_facilityType isEqualTo "foodL") then {
		0 = [_storposit, 360, call (compile (preprocessFileLineNumbers "Compositions\foodstor_s.sqf"))] call BIS_fnc_ObjectsMapper;
	};

	if (_facilityType isEqualTo "workshopS") then {
		0 = [_storposit, 360, call (compile (preprocessFileLineNumbers "Compositions\foodstor_s.sqf"))] call BIS_fnc_ObjectsMapper;
	};

	if (_facilityType isEqualTo "workshopL") then {
		0 = [_storposit, 360, call (compile (preprocessFileLineNumbers "Compositions\foodstor_s.sqf"))] call BIS_fnc_ObjectsMapper;
	};

	if (_facilityType isEqualTo "storageS") then {

		hint "this";
		private _choice = selectRandom [1,2];

		if (_choice isEqualTo 1) then {
			0 = [_storposit, 360, call (compile (preprocessFileLineNumbers "Compositions\AmmoStorage.sqf"))] call BIS_fnc_ObjectsMapper;
		} else {
			0 = [_storposit, 360, call (compile (preprocessFileLineNumbers "Compositions\AmmoStorage_2.sqf"))] call BIS_fnc_ObjectsMapper;
		};
	
	};
};

 

 

Thanks!

Share this post


Link to post
Share on other sites

what does that do, and why does it work? I have that in another script, and it works perfectly but I don't understand it!

Share this post


Link to post
Share on other sites

@anaximandross, according to BIKI, 4th element of _this (_this select 3) is your arguments (_plotArray2, b2_term) passed to CreateBasePlots.sqf.

Share this post


Link to post
Share on other sites
5 minutes ago, Schatten said:

@anaximandross, according to BIKI, 4th element of _this (_this select 3) is your arguments (_plotArray2, b2_term) passed to CreateBasePlots.sqf.

Oh ok, that makes sense! Thanks! So, that first script works just fine now. Do you have any ideas on how to pass the locations to the second script, the assembler? Right now its throwing this error:

 

Spoiler

14:48:55 Error in expression <tyType","_facilityCost"];

_storPosit = getPos  _this;

hint format ["%1",_storp>
14:48:55   Error position: <getPos  _this;

hint format ["%1",_storp>
14:48:55   Error getpos: Type Array, expected Object,Location

 

 

Share this post


Link to post
Share on other sites

@anaximandross, similarly:

(_this select 3) params ["_facilityPositon", "_facilityType", "_facilityCost"];

But you pass only 2 arguments to assembler.sqf (e.g. [_position, "foodS"]).

What's difference between _storPosit and _facilityPositon?

Share this post


Link to post
Share on other sites

There isn't one. I think I was having some sort of issue with locality, so I set _storPost = getPos _facilityPosition. but I changed it to _this to see if that would work. 


When I added that line, it threw this error: 

 

Spoiler

(_this select 3) params ["_facilityPositon", "_>
15:10:48   Error position: <select 3) params ["_facilityPositon", "_>
15:10:48   Error getpos: Zero divisor

 

 

Share this post


Link to post
Share on other sites
11 hours ago, Schatten said:

@anaximandross, provide your modified assembler.sqf please. What parameters do you pass to the script?

@Schatten Sure! Here it is. 

 

Spoiler

if(!isServer) exitWith {}; 

(_this select 3) params ["_facilityPositon", "_facilityType", "_facilityCost"];

_storPosit = getPos  _this;

hint format ["%1",_storposit];

if(GLOBALSCRAP > _facilityCost)  then {

	if (_facilityType isEqualTo "foodS") then {
		0 = [_storposit, 360, call (compile (preprocessFileLineNumbers "Compositions\foodstor_s.sqf"))] call BIS_fnc_ObjectsMapper;

	};

	if (_facilityType isEqualTo "foodL") then {
		0 = [_storposit, 360, call (compile (preprocessFileLineNumbers "Compositions\foodstor_s.sqf"))] call BIS_fnc_ObjectsMapper;
	};

	if (_facilityType isEqualTo "workshopS") then {
		0 = [_storposit, 360, call (compile (preprocessFileLineNumbers "Compositions\foodstor_s.sqf"))] call BIS_fnc_ObjectsMapper;
	};

	if (_facilityType isEqualTo "workshopL") then {
		0 = [_storposit, 360, call (compile (preprocessFileLineNumbers "Compositions\foodstor_s.sqf"))] call BIS_fnc_ObjectsMapper;
	};

	if (_facilityType isEqualTo "storageS") then {

		hint "this";
		private _choice = selectRandom [1,2];

		if (_choice isEqualTo 1) then {
			0 = [_storposit, 360, call (compile (preprocessFileLineNumbers "Compositions\AmmoStorage.sqf"))] call BIS_fnc_ObjectsMapper;
		} else {
			0 = [_storposit, 360, call (compile (preprocessFileLineNumbers "Compositions\AmmoStorage_2.sqf"))] call BIS_fnc_ObjectsMapper;
		};
	
	};
};

 

 

Share this post


Link to post
Share on other sites

@anaximandross, as I expected, I got this error:

22:45:19 Error in expression <facilityCost"]; 
 
        _storPosit = getPos _this; 
    >
22:45:19   Error position: <getPos _this; 
    >
22:45:19   Error getpos: Type Object, expected Array,Location

I don't understand how you got your error.

 

Spoiler

Here is test snippet:


player addAction [
    "Action",
    {
        (_this select 3) params ["_facilityPositon", "_facilityType", "_facilityCost"];

        _storPosit = getPos _this;
    },
    [[0, 0], "foodS"]
];

Share this post


Link to post
Share on other sites
2 hours ago, Schatten said:

@anaximandross, as I expected, I got this error:


22:45:19 Error in expression <facilityCost"]; 
 
        _storPosit = getPos _this; 
    >
22:45:19   Error position: <getPos _this; 
    >
22:45:19   Error getpos: Type Object, expected Array,Location

I don't understand how you got your error.

 

  Reveal hidden contents

Here is test snippet:



player addAction [
    "Action",
    {
        (_this select 3) params ["_facilityPositon", "_facilityType", "_facilityCost"];

        _storPosit = getPos _this;
    },
    [[0, 0], "foodS"]
];

Hmm, let me retest it and see what I get. How do I fix the error that you got though?

 

Also, what is that test snippet for?

EDIT: When I changed it to (_this select 2) params ["....]; it threw the same error as yours did.

 

Spoiler


hint format ["%1",_storp>
17:24:07   Error position: <getPos  _this;

hint format ["%1",_storp>
17:24:07   Error getpos: Type Array, expected Object,Location

 

 

 

Share this post


Link to post
Share on other sites
20 hours ago, anaximandross said:

How do I fix the error that you got though?

It depends on what position you want to get.

As you can see, _this is not object or location, so you need to replace it.

 

20 hours ago, anaximandross said:

Also, what is that test snippet for?

This is to reproduce the error you got.

Share this post


Link to post
Share on other sites

@anaximandross, you just need to read BIKI and use what you need. In script you can use:

_this select 0 -- the object which the action is assigned to

_this select 1 -- the unit that activated the action

_this select 2 -- ID of the activated action

_this select 3 -- arguments given to the script if you are using the extended syntax (in your case array [position] and string)

 

Share this post


Link to post
Share on other sites

Oh my gosh, I never even read that section. Thank you for the help! I should be able to figure that out now. Thank you so much! 🤦‍♂️

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  

×