- Home /
Question by
FinarFlyGames · Oct 07, 2016 at 06:26 PM ·
array list
Adding class element from existing array into another array
Case:
public class items
{
var itemName : String;
var itemID : int;
var itemPrice : int;
}
var itemList : items[];
var ownedItems : items[];
How can i add, for example, an element from itemList to ownedItems. It looks something like this:
ownedItems.Add(itemList[0]);
I've tried Array.Add(); method but it didn't work. JS Only
Comment
You can assign values to elements of an array with myArray[n] = myValue.
Arrays have a fixed size which is decided when they are initialized. If you want to add and remove elements and make the collection grow and shrink accordingly, use a List. Barring, that, you can always create a temporary array with the required Length, add your elements to it, and assign it to the existing array variable.