Home   Help Search Login Register  

Author Topic: nested array _x select 0 setpos _x select 2  (Read 1358 times)

0 Members and 1 Guest are viewing this topic.

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
nested array _x select 0 setpos _x select 2
« on: 18 Jan 2006, 17:15:56 »
I have a nested array, each element has 4 subset elements

What i am trying to do is optimise some code so as the reduce the commands to a handful of lines

subset element  (_x select 0) setpos (_x select 3)

this is the script / array

Code: [Select]
;;; txA_sectors subarray breakdown
;; _x select 0 = value, either 0 or 1
;; _x select 1 = sector marker
;; _x select 2 = sector Logic
;; _x select 3 = sector central  position
txA_sectors = [  [txB_S1, "S1m", S1L, [10500, 10300, 0] ] ,[txB_S2, "S2m", S2L, [10500, 11300, 0]], [txB_S3, "S3m", [10500, 12300 ,0]],[txB_S4, "S4m", [ 9500,  10300, 0]],[txB_S5, "S5m",  [ 9500,  11300, 0]],[txB_S6, "S6m",[ 9500,  12300, 0]], [txB_S7, "S7m", [8500,   10300, 0]],[txB_S8, "S8m", [8500,   11300, 0]],[txB_S9, "S9m",[8500,   12300, 0]],[txB_S10, "S10m",[7500,   10300, 0]],[txB_S11, "S11m",[7500,   11300, 0]] ]

and the commands i want to run are

subarray select 1 setmarkerpos subarray select 3 foreach txA_sectors
subarray select 2 setpos subarray select 3 foreach txA_sectors
code i initially tried was

{(_x select 1) setmarkerpos (_x select 3)}foreach txA_sectors
if (local server)then{(_x select 2) setpos (_x select 3)foreach txA_sectors


which doesnt work

I'm now trying something on the lines of
initiating  local values for _x select within the "If" statement, but cant get the syntax correct


eg using a statement in similar layout to the following examplesome
 {_y=_x;{_x reveal _y}forEach wgl_zEunits}forEach wgl_zWunits

Please dont post with a reply
"why dont you simply do the following
"S1m",setmarkerpos [10500, 10300, 0]
S1L, setpos [10500, 10300, 0]



Any help would be appreciated before i go completely bald ;D
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re:nested array _x select 0 setpos _x select 2
« Reply #1 on: 18 Jan 2006, 18:13:20 »
Have you tried with "?

Code: [Select]
"(_x select 1) setmarkerpos (_x select 3)" forEach txA_sectors
"if (local server)then{(_x select 2) setpos (_x select 3)" forEach txA_sectors


Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:nested array _x select 0 setpos _x select 2
« Reply #2 on: 18 Jan 2006, 18:27:03 »
for the record, "" and {} are interchangeable in flashpoint scripts...

i spent a few minutes grappling with the problem this afternoon, but what you have already tried is what i'd have suggested. it seems that you may have to grab the sub-arrays first, and then use the foreach command, but as you say, that's not optimal, and probably wouldn't work...

(where's a THobson when you need one... ;) )

/more
« Last Edit: 18 Jan 2006, 18:30:18 by bedges »

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:nested array _x select 0 setpos _x select 2
« Reply #3 on: 18 Jan 2006, 19:12:19 »
code used

{(_x select 1) setmarkerpos (_x select 3)}foreach txA_sectors




I changed the markers to a X marker and had each marker have a number,(Initially they were simply solid filled boxes)  so that i could see exactly what is happening

My findings

The markers setpos for the first 2 subarrays, after that i get an error message


 I then added a sidechat  format

{(_x select 1) setmarkerpos (_x select 3);player sidechat format ["Marker = %1... Pos = %2",(_x select 1),(_x select 3)]}foreach txA_sectors


to try and determine what it saw as the _x selects, and only 2 instances were printed out, stopping on the third cycle and issuing the following error message



'(_x select 1) setmarkerpos (_x select 3)|#|' Error setmarkerpos: Type string: Expected array

anyone any idea whats happening, cant even figure out how to debug the damned thing
« Last Edit: 18 Jan 2006, 19:13:37 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:nested array _x select 0 setpos _x select 2
« Reply #4 on: 18 Jan 2006, 19:30:36 »
Seems to me that your array definition is at fault.

txB_S3 - txB_S11 have no sector Logic component, whilst txB_S1 and txB_S2 do.
Code: [Select]
txA_sectors = [[txB_S1, "S1m", S1L, [10500, 10300, 0]], [txB_S2, "S2m", S2L, [10500, 11300, 0]],
[txB_S3, "S3m", S3L, [10500, 12300 ,0]], [txB_S4, "S4m", S4L, [ 9500, 10300, 0]], [txB_S5, "S5m",
S5L, [ 9500, 11300, 0]], [txB_S6, "S6m", S6L, [ 9500, 12300, 0]], [txB_S7, "S7m", S7L, [8500, 10300,
0]], [txB_S8, "S8m", S8L, [8500, 11300, 0]], [txB_S9, "S9m", S9L,[8500, 12300, 0]], [txB_S10, "S10m",
S10L,[7500, 10300, 0]], [txB_S11, "S11m", S11L,[7500, 11300, 0]] ]

Like so......maybe


Planck
« Last Edit: 18 Jan 2006, 19:37:53 by Planck »
I know a little about a lot, and a lot about a little.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:nested array _x select 0 setpos _x select 2
« Reply #5 on: 18 Jan 2006, 19:32:28 »
it's your array.

[ [txB_S1, "S1m", S1L, [10500, 10300, 0] ] ,[txB_S2, "S2m", S2L, [10500, 11300, 0]], [txB_S3, "S3m", [10500, 12300 ,0]]......

first sub array = 4 elements
second sub array = 4 elements
third sub array = 3 elements

;)

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:nested array _x select 0 setpos _x select 2
« Reply #6 on: 18 Jan 2006, 19:42:41 »
lol, u beat me too it, i just realised, what a plonker
i should have realised when it didnt run the 3rd subarray, where the problem lay
« Last Edit: 18 Jan 2006, 19:56:06 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:nested array _x select 0 setpos _x select 2
« Reply #7 on: 18 Jan 2006, 19:46:38 »
Just one of those cases where it takes a fresh pair of eyes.......or two........to spot these things.


Planck
I know a little about a lot, and a lot about a little.