Jump to content
Sign in to follow this  
Linker Split

Function to save inventory

Recommended Posts

Hello guys,

I'm having a problem with a function which should return me an array of objects with they damage, but it's not working properly.

The function I've written is:

EPfn_saveInventory =
{
private["_array"];
_array  = [] + _this;
{
	if ((typeName _x) == "ARRAY") then
	{
		_item = _x select _forEachIndex;
		_type = typeOf _item;
		_dam = damage _item;
		_newArr = [_type,_dam];
		_x set [_forEachIndex,_newArr];
	}
	else
	{
		diag_log "THIS IS NOT AN ARRAY";
	};
}forEach _array;
_array
};

It's called like this:

_items = _items call EPfn_saveInventory;

Where _items is an ARRAY of object a player got in his inventory.

So I should fill the array of a tent with the objects that I put inside it.

I must say that the line where the function is called, is a loop too.

Edited by Linker Split

Share this post


Link to post
Share on other sites

Try to use this function:

EPfn_saveInventory = {
private ["_array", "_items"];

_array = [];

{
	if ((typeName _x) == "ARRAY") then {
		_items = _x;

		{
			_array set [
				count _array,
				[
					typeOf _x,
					damage _x
				]
			];
		}
		forEach _items;
	}
	else {diag_log "THIS IS NOT AN ARRAY"};
}
forEach _this;

_array
};

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  

×