OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Terox 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
;;; 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
-
Have you tried with "?
"(_x select 1) setmarkerpos (_x select 3)" forEach txA_sectors
"if (local server)then{(_x select 2) setpos (_x select 3)" forEach txA_sectors
-
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
-
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
-
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.
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
-
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
;)
-
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
-
Just one of those cases where it takes a fresh pair of eyes.......or two........to spot these things.
Planck