Home   Help Search Login Register  

Author Topic: Getting the variable from a "double-array"  (Read 526 times)

0 Members and 1 Guest are viewing this topic.

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Getting the variable from a "double-array"
« on: 30 Oct 2004, 22:36:27 »
Hellöw all.

I have a slight situation 'ere. You see, arrays are really powerful, though I'm not really good with 'em. I have this double array which is built up like this:

dudearray = [["Whatever", 2, 3, 1, 6], ["Whatever2", 2, 8, 3]]

Now, I wanna access the elements in those array-arrays, so to speak. You guys understand? Cheers for the help!

:beat: *Gets Shot* :beat:

Offline Killswitch

  • Members
  • *
  • Peace, cheese and ArmA
Re:Getting the variable from a "double-array"
« Reply #1 on: 31 Oct 2004, 01:40:17 »
I have a slight situation 'ere. You see, arrays are really powerful, though I'm not really good with 'em. I have this double array which is built up like this:

dudearray = [ ["Whatever", 2, 3, 1, 6], ["Whatever2", 2, 8, 3] ]

Now, I wanna access the elements in those array-arrays, so to speak. You guys understand? Cheers for the help!
Quite. The first element of that two-element array you would get by doing
Code: [Select]
firstelement = dudearray select 0The result of that operation would be that firstelement would have the value ["Whatever",2,3,1,6].
To get the second element of dudearray one would do
Code: [Select]
secondelement = dudearray select 1That operation would make secondelement have the value ["Whatever2",2,8,3].

Summary: in this example, dudearray is an array of arrays aka a multi-dimensional array. As you can see, the elements of that array are arrays too.

<Bad-grammar Yoda> From these basics, neat stuff, be made can.</Bad-grammar>

Offline Blanco

  • Former Staff
  • ****
Re:Getting the variable from a "double-array"
« Reply #2 on: 31 Oct 2004, 05:31:10 »
To select an element in one of the arrays you have this...
Code: [Select]
_array = [ 33,79, [s4,20,1], 25]
_a = (_array select 2) select 1

Select 2 means you are selecting the 3 element in the whole array
That's [s4,20,1]
select 1 is the second element in that array,
so _a = 20

other example

Code: [Select]
_array = [ [1,"hello"], [L4,20,1], 25]
_b = (_array select 0) select 1

select 0 is the array [1,"hello"]
select 1 is the second element  in that array
_b = "hello"
« Last Edit: 31 Oct 2004, 05:35:15 by Blanco »
Search or search or search before you ask.

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:Getting the variable from a "double-array"
« Reply #3 on: 31 Oct 2004, 08:39:19 »
OK, that's good stuff. Cheers! :)

:beat: *Gets Shot* :beat: