Really quick question, but i can’t find answers…
I have a public “ArrayList entityID = new ArrayList()”, and inside it i stored a “PlayerArray = new int[10]”, wich has been previously modified to have “PlayerArray[0] = AnotherIntegerVariable”, and i know that it will always be the 1st array in the list; how do i access the array’s data?
For example: how do i know if the first value of the stored array == 1?
Thanks in advance
Hi,
Can you show example code of your setup so far, I’m not sure if I understand correctly what you’re trying to do.
This is my list, inside the “EntityScript” script, attached to the “LevelRuler” object.
public ArrayList entityID = new ArrayList();
Here i add the array to the list (from another script), after changing the first 2 values of it:
void Start()
{
PlayerArray = new int[10];
}
void Click_Rogue_btn()
{
PlayerArray[0] = 1;
PlayerArray[1] = variabeX; //this variable is an int. i can change it before adding it to the list if i want.
LevelRuler.GetComponent<EntityScript>().entityID.Add(PlayerArray);
}
My question is: how do i check if the array (inside the list) that has “1” at position [0] has a specific value in the position [1]?
So because the list will have more arrays inside it, i need to find the one that has “1” as its first value (value that i only give for this purpouse of identifying) and then check if its second value is a specific number (in my case variableX is 2)
Don’t use ArrayList, use List<>. ArrayList is old and bad and hard to use.
Hard to say with the limited snippet you posted, but I think you want a List<int[ ]>? Basically, a list of arrays? To access it, you could do something like:
List<int[]> myListOfArrays = new List<int[]>();
myListOfArrays.Add(PlayerArray);
foreach (int[] thisArrayWithinList in myListOfArrays) {
Debug.Log($"Item 0 of this array is {thisArrayWithinList[0]}");
}