Jump to content
Sign in to follow this  
eagledude4

Array to string array

Recommended Posts

How can I convert an object array to a string array?

for example: [civ1,civ2,civ3] to ["civ1","civ2","civ3] ?

Edited by eagledude4

Share this post


Link to post
Share on other sites

civ1,civ2,civ3 etc are objects yea? If so you would want to do this.

civarray = [civ1,civ2,civ3,civ4,civ5,civ6,civ7,civ8,civ9,civ10,civ11,civ12,civ13,civ14,civ15,civ16,civ17,civ18,civ19,civ20,civ21,civ22,civ23,civ24,civ25,civ26,civ27,civ28,civ29,civ30];
coparray = [cop3,cop4,cop5,cop6,cop7,cop8,cop9,cop10,cop11,cop12,cop13];

playerarray = civarray + coparray;
playerstringarray = [];

for "_i" from 0 to (count playerarray) do
{
_player = (vehicleVarName (playerarray select _i));
playerstringarray = playerstringarray + [_player];
};

Share this post


Link to post
Share on other sites

You need the command: str , it converts any variable to a string:

eg to check the array on modelToWorld:

_worldPos = [6,6,6];
_x = 6;_y = 6;_z = 6;
if (format ["%1",_worldPos] == str[_x,_y,_z]) then {hint "location Ozzy Osbourne found";};

str[_x,_y,_z] == "[6,6,6]"

format ["%1",_worldPos] == "[6,6,6]"

Do you want the whole array as 1 string (as above) or each element converted to a string? as in:

[1,2,3] to ["1","2","3"]

nul = [] execVM "stringArrayCnv.sqf";

_array1 = [1,2,3];
_array2 = [];
for "_i" from 0 to (count _array1 - 1) do {
   _array2 set [_i, str(_array1 select _i)];
 };
player sidechat format ["%1",_array2];

Edited by Mattar_Tharkari

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  

×