OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Luke on 23 Jul 2008, 01:43:04

Title: Backwards select (Solved)
Post by: Luke on 23 Jul 2008, 01:43:04
Hey all,

I was wondering if it was possible if you could get the select # of an array, like:

_array=[_array] + [_thing1]
_array=[_array] + [_thing2]
_array=[_array] + [_thing3]
_thing2 ""command"" _array returns "select 1"

Let me know if/when you find something.

Luke
Title: Re: Backwards select
Post by: Mandoble on 23 Jul 2008, 02:54:01
I dont understand your question, much less your example, anyway might be this is what you are looking for:
Code: [Select]
_array = [];
_array=_array + [_thing1];
_array=_array + [_thing2];
_array=_array + [_thing3];
// (_array select 1) is _thing2
Title: Re: Backwards select
Post by: Luke on 23 Jul 2008, 04:16:14
Quite possibly.

Very specifically, what i am looking for is a function/command, that if I provide a name and an array, this command will tell me what select number the name is in the array.

Luke
Title: Re: Backwards select
Post by: Cheetah on 23 Jul 2008, 08:25:06
So you want a command like the php function array_search (http://www.php.net/manual/en/function.array-search.php).

Searches the array for a given value and returns the corresponding key if successful.

EDIT: see attached files.
Title: Re: Backwards select
Post by: Wolfrug on 23 Jul 2008, 09:13:47
Umm.

There is actually already a function for that, nicely named find (http://community.bistudio.com/wiki/find). ;) I won't link to the COMREF one since the example is wrong, but basically:

Code: [Select]
_name = "Doodle";
_array = ["Doodle", 146, lollerskates];
_nr = _array find _name;
hint format ["%1 is number %2 in the array %3", _name, _nr, _array];

Should do it :)

Wolfrug out.
Title: Re: Backwards select
Post by: Cheetah on 23 Jul 2008, 09:17:41
Thought that there was such a function, but couldn't find it in the COMREF  :whistle:
Title: Re: Backwards select
Post by: Mandoble on 23 Jul 2008, 09:36:45
If it is a matter of looking for a value inside an array:
Code: [Select]
_array = ["A", "B", "C"];
_index = _array find "C";
// _index = 2

Code: [Select]
_array = ["A", "B", "C"];
_index = _array find "H";
// _index = -1
Title: Re: Backwards select
Post by: Luke on 23 Jul 2008, 18:40:18
Mando,

This (http://ca.youtube.com/watch?v=Up3TIPoVh-M&feature=related) is for you!!  :D

Thanx a LOT.  :)

Luke