Accessing elements of a nested array

rosska85

Valued Member!
Think it's a nested array anyway, still new to them.

Essentially, what I'm doing is storing some information to an array associated to a variable. I can get the information to store perfectly, but I'm having issues on trying to retrieve it.
I'm storing the data like this
[["DataType1"],["DataType2","DataType2","DataType2"]]

I want to keep them separated like this because DataType1 will only ever have one entry, whereas DataType2 will have multiple player UIDs stored to it.

I'm just not sure how to check for a value within the arrays though. I tried doing something like this


Code:
_realdata = cursorTarget getVariable ["NameofArrayVariable", [], true];
_useabledata = _realdata select 1;
_canUse = ((getPlayerUID player) in _useabledata);


Though that doesn't ever work, and I've read that you can't use 'in' with nested arrays, so I'm not sure if it's because of that or if it's because I'm simply not telling it to read the array correctly.

I've read through the tutorials on arrays via CommanderRetra's post several times now and I swear I'm just hitting my head off the keyboard at this point. I know it's clearly doable, I just don't know how.

I also know my array is storing the data correctly because I can see the data in there, also it worked when it was just a singular array like [DataType2,DataType2] I could check the UIDs fine against that, it's just this nested thing that's going awry.

I'd really appreciate any advice, thanks.
 
un-nest the arrays
_data1 = _this select 0;
_data2 = _this select 1;
_uid = _data2 select _x;

or; you could try this from Toejam..
Code:
//Created by [CPC] ToejaM - www.CPC-Gaming.eu
Waituntil{!isNull player};
 
while{true} do {
sleep 0.5;
if((isPlayer cursorTarget) && (alive cursorTarget) && (side cursorTarget == side player) && (player distance cursorTarget < 10)) then {
_tag = name cursorTarget;
cutText [_tag,"PLAIN",0.1];
 
} else {
};
};
and replace name cursorTarget with getPlayerUID cursorTarget
 
un-nest the arrays
_data1 = _this select 0;
_data2 = _this select 1;
_uid = _data2 select _x;

or; you could try this from Toejam..
Code:
//Created by [CPC] ToejaM - www.CPC-Gaming.eu
Waituntil{!isNull player};
 
while{true} do {
sleep 0.5;
if((isPlayer cursorTarget) && (alive cursorTarget) && (side cursorTarget == side player) && (player distance cursorTarget < 10)) then {
_tag = name cursorTarget;
cutText [_tag,"PLAIN",0.1];
 
} else {
};
};
and replace name cursorTarget with getPlayerUID cursorTarget

Not too sure I follow you on that second part, don't know what that would achieve.

Essentially, what I'm wanting to do, is store playerUIDs in an array, then only grant players access provided their UID is in the array. That part worked fine. The problem arose when I came to adding other data I also wanted to store in the Array for later use, thus having to use nested arrays, and my inability to compare the playerUID to the stored UIDs in the array.

Edit: I've now changed my array structure slightly so it goes like this
["DataType1",["DataType2","DataType2"]]
In the hopes that it may make things easier... Doesn't seem to be though.
 
Ok figured it out. It was indeed to do with the fact I couldn't use 'in' with nested arrays. Switched it round a little and did it like this in the end and it works.

Code:
    _realdata = cursorTarget getVariable ["NameofArrayVariable", []];
        {
            _dataType2 = _x select 1;
            _canUse = if (_x == (getPlayerUID player)) then {true} else {false};
        } forEach _dataType2;

I know it looks strange that I'm storing two arrays and only calling one, but for this specific section I only needed the second array.
 
Back
Top