Jump to content
Sign in to follow this  
Robustcolor

Help with array.

Recommended Posts

Hi, I'm trying to have an array with editor placed map markers inside. My goal is to have main markers attached with sub markers, something like below. Tips?

_markers = [["1",["m1_1","m1_2"]],["2",["m2_1","m2_2"]]];

_target = selectRandom _markers;

/example/

_target = ["1",["m1_1","m1_2"]];

From here, i can't seem to fetch the positions of the markers.

_mainTarget select 0 gives me "1" but i can't use getMarkerPos on it.

Same here,

_subTargets = _target select 1;

selectRandom _subTargets;

_subTarget gives me "m1_1";

 

Share this post


Link to post
Share on other sites

I think this should work in the end:

 

_subTarget = selectRandom _subTargets;

_mpos = getMarkerPos _subTarget;
  • Like 3

Share this post


Link to post
Share on other sites

@Robustcolor, if you don't need main marker names, then you can simplify the code:

_markers = [["m1_1", "m1_2"], ["m2_1", "m2_2"]];

_subTarget = selectRandom (selectRandom _markers);

If you need main marker names, then you can use either this code:

_markers = [["1", ["m1_1", "m1_2"]], ["2", ["m2_1", "m2_2"]]];

_subTarget = selectRandom ((selectRandom _markers) select 1);

or this one:

_markersHashMap = createHashMap [["1", ["m1_1", "m1_2"]], ["2", ["m2_1", "m2_2"]]];

_subTarget = selectRandom (_markersHashMap get (selectRandom (keys _markersHashMap)));

 

  • Like 3

Share this post


Link to post
Share on other sites

Is it possible to store positions inside the array with apply {getMarkerPos _x} when the array looks like this?

_markers = [["1",["m1_1","m1_2"]],["2",["m2_1","m2_2"]]];

Because this will be in a loop and it will fetch the position again for each check.

5 hours ago, gc8 said:

_subTarget = selectRandom _subTargets;

_mpos = getMarkerPos _subTarget;

Share this post


Link to post
Share on other sites
13 hours ago, Robustcolor said:

Because this will be in a loop and it will fetch the position again for each check.

 

If you are thinking about speed I wouldn't bother. Now the code would be smaller and easier to read, without extra loop.

That's just my opinion of course

 

  • Like 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×