Jump to content

Recommended Posts

I'm a bit confused as to what your up to exactly..., but I think you're looking for something like a hash-table/map (or a dictionary). That is, given a classname (e.g. "B_G_Van_01_fuel_F") you'd like to retrieve some further information - in this case the price, for which you are bookkeeping your table.

Given your _vehicle_prices, you can do a linear search by iterating over all entries, while comparing keys, as in:

_key = "B_G_Van_01_fuel_F"; // key we want to know/look up it's price
_price = -1;

{
  if (_key == (_x select 0)) exitWith { _price = _x select 1; };
} forEach _vehicle_prices;

// return price, -1 if not found
_price

But you can do better, by keeping keys (i.e. your classnames) and data (prices here) in separate arrays, since you can then leverage the speed of the find command:

_keys = [];
_prices = [];
{
  _keys pushBack (_x select 0);
  _prices pushBack (_x select 1);
} forEach _vehicle_prices; // just do this once at startup

// now to search:
_key = "B_G_Van_01_fuel_F"; // key we want to know/look up it's price
_idx = _keys find _key;
if (_idx < 0) exitWith { -1 }; // not found

// otherwise _idx now points to the correct price
(_prices select _idx)

Depends if you need that speed; and if so, you could consider using some extra-dictionary code/functions to make such work way nicer.

In order to not have to fill in the data manually into separate arrays (seems to be errorprone), you can do something like this:

_keys = [];
_prices = [];
{
  _keys pushBack (_x select 0);
  _prices pushBack (_x select 1);
} forEach [
  ["I_Heli_light_03_unarmed_F",20000],	
  ["B_G_Van_01_fuel_F",5000],			
  ["B_G_Van_01_transport_F",5000]
];

...instead of defining some _vehicle_prices first.

Does that help?

:D

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  

×