Jump to content
rness

Manipulate multi-array

Recommended Posts

Hi,

 

Can you help me for a little script?

I have a array and i want add mutli-array, pick random value of each array, and modify a marker position.


1/ Simple array :
_array = ["toto","titi",tata"];

2/ I want auto generate a multi array with addition (_1 _2 and _3) :
--> _mutliarray = [["toto_1", "toto_2", "toto_3"],["titi_1", "titi_2", "titi_3"],["tata_1", "tata_2", "tata_3"]];

 3/ And auto select random value form each mutliarray:
_result = _mutliarray floor random count _mutliarray;
// example return for toto: "toto_1" or "toto_2" or "toto_3"

// same with another value: "titi_1" or "titi_2" or "titi_3" and "tata_1", "tata_2", "tata_3"

 

4/ Change marker position :
"toto_1" setMarkerPos getMarkerPos _result_toto;

"tata_1" setMarkerPos getMarkerPos _result_tata;

"titi_1" setMarkerPos getMarkerPos _result_titi;


I think i need something like this?

private _array = ["toto","titi",tata"];
{
private _current = _array select _x;
        for "_x" from 0 to 3 do    {
            private _currentElement = _current+"_"+_x;
         };

          private _result = _currentElement select floor random count _currentElement;

          _current setMarkerPos getMarkerPos _result;
} forEach _array;

Thanks for your help.

 

Regards
 

Share this post


Link to post
Share on other sites
10 minutes ago, rness said:

2/ I want auto generate a multi array with addition (_1 _2 and _3) :
--> _mutliarray = [["toto_1", "toto_2", "toto_3"],["titi_1", "titi_2", "titi_3"],["tata_1", "tata_2", "tata_3"]];

 

// So
private _multiarray = ["A", "B", "C"] apply {private _pre = _x; [1, 2, 3] apply {_pre + "_" + str _x}};
// Or
private _multiarray = ["A", "B", "C"] apply {private _pre = _x; [1, 2, 3] apply {format ["%1_%2", _pre, _x]}};
// Result:
// [["A_1","A_2","A_3"],["B_1","B_2","B_3"],["C_1","C_2","C_3"]]

// Selecting
private _chosen = _multiarray apply {selectRandom _x};
// Result:
// ["A_3","B_1","C_2"]

 

  • Like 1

Share this post


Link to post
Share on other sites

Hi

here's a code that should do what you wanted (if I understood correctly)

_randomPositions = [["toto_1", "toto_2", "toto_3"],["titi_1", "titi_2", "titi_3"],["tata_1", "tata_2", "tata_3"]];
_markers = ["toto","titi","tata"];
{
 _marker = _x;
 _ranpositions = _randomPositions select _forEachIndex;
 _pos = selectRandom _ranpositions;
 _marker setMarkerPos (getMarkerPos _pos);
} foreach _markers;

 

  • Like 1

Share this post


Link to post
Share on other sites

Amazing :)
Thanks a lot for your answers!
 

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

×