Jump to content
Sign in to follow this  

Recommended Posts

Hi everyone !

 

I'm stuck on something, i'd like to count items on a container. but I'd like to count _x for a group of item. I explaine myself :

 

Every day (ingame) I check with a script if the box "Box" contain a certain amount of items, let's say that I check if there is some food in it.

 

So I'd like to count if there is enough food (like 10 food item) in the box container, but it can be 2 carrots / 1 fish / 4 chickens etc... and I don't want to count like : _nbChicken = {"chicken" == _x} count (itemCargo MyBox); _nbFish = {"Fish" == _x} count (itemCargo MyBox);  _nbFood = _nbChicken + _nbFish......

I'd like to make it this way : 

 

_table = ["Fish","chicken",etc....];

_nbFood = {_table == _x} count (itemCargo MyBox);

is this possible ?
 

Share this post


Link to post
Share on other sites

Assuming those are actual items that you or a mod has added then you can do:

_table = ["Fish", "chicken", "escargot"];
_nbFood = {_x in _table} count (itemCargo MyBox);

 

Share this post


Link to post
Share on other sites
4 hours ago, HazJ said:

Assuming those are actual items that you or a mod has added then you can do:


_table = ["Fish", "chicken", "escargot"];
_nbFood = {_x in _table} count (itemCargo MyBox);

 

Keep in mind that that is case sensitive.

_table = ["fish", "chicken", "escargot"];
_nbFood = {(toLower _x) in _table} count (itemCargo MyBox);

That would be the safe route.

  • Like 1

Share this post


Link to post
Share on other sites
22 minutes ago, Dedmen said:

Keep in mind that that is case sensitive.


_table = ["fish", "chicken", "escargot"];
_nbFood = {(toLower _x) in _table} count (itemCargo MyBox);

That would be the safe route.

This would fail if there's a single upper case typo in one element inside _table in case of user error.

 

To actually be safe do this:

_table = ["fish", "chicken", "escargot"] apply {toLower _x};
_nbFood = {(toLower _x) in _table} count (itemCargo MyBox);

If you check one element as lowerCase make sure the array you're checking against also only contains lowercase.

 

Cheers

  • 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  

×