Home   Help Search Login Register  

Author Topic: Backwards select (Solved)  (Read 1535 times)

0 Members and 1 Guest are viewing this topic.

Offline Luke

  • Members
  • *
  • Thank God! The OFPEC Staff are here!
Backwards select (Solved)
« 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
« Last Edit: 23 Jul 2008, 23:39:21 by Luke »
Pesky Human!!
Wort Wort Wort.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Backwards select
« Reply #1 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

Offline Luke

  • Members
  • *
  • Thank God! The OFPEC Staff are here!
Re: Backwards select
« Reply #2 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
Pesky Human!!
Wort Wort Wort.

Offline Cheetah

  • Former Staff
  • ****
Re: Backwards select
« Reply #3 on: 23 Jul 2008, 08:25:06 »
So you want a command like the php function array_search.

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

EDIT: see attached files.
« Last Edit: 23 Jul 2008, 09:01:47 by Cheetah »
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Backwards select
« Reply #4 on: 23 Jul 2008, 09:13:47 »
Umm.

There is actually already a function for that, nicely named 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.
"When 900 years YOU reach, look as good you will not!"

Offline Cheetah

  • Former Staff
  • ****
Re: Backwards select
« Reply #5 on: 23 Jul 2008, 09:17:41 »
Thought that there was such a function, but couldn't find it in the COMREF  :whistle:
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Backwards select
« Reply #6 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

Offline Luke

  • Members
  • *
  • Thank God! The OFPEC Staff are here!
Re: Backwards select
« Reply #7 on: 23 Jul 2008, 18:40:18 »
Mando,

This is for you!!  :D

Thanx a LOT:)

Luke
Pesky Human!!
Wort Wort Wort.