Argument is not enumerable error when trying to get int from separate class

Hey all.

I’m making an inventory and trying out JavaScript classes for the first time, looking for some help.

I have a bag class, which has various elements like bagType, Name, etc. I also have a bagSlots int in that class, which is how many inventory slots the bag has. I have a simple pick up dynamic working: you click on an item, it saves to an itembeingdragged variable (of type Bag). I can then transfer this itemBeingDragged to a gui button I have set up. Clicking on that button will open that bag.

My problem is with the bag slots. I’d like different bags with different numbers of slots (small bags with 4 slots, medium with 6, etc). But I don’t know how to point to that number correctly when trying to create the slots in a loop. This is the function that’s not working, it’s in a separate inventory js file.

function DisplayBagAInventoryWindow (windowID :int){
var index=0;
		for(var a in bagSlotA.bagSlots){
		
			if(GUI.Button(inventorySlots[index],"Slot: " + index)){
			}	

		index++;	
		}
}

That gives me the following error : “ApplicationException: Argument is not enumerable (does not implement System.Collections.IEnumerable).” and points to the line with the for loop.

Bag Class below:

#pragma strict

public class Bag {	

	var itemType : ItemType;
	var bagSize : bagSize;
	var name : String;
	var desc : String;
	var itemIcon : Texture2D;
	
	var equipped : boolean;
	var bagSlots : int;

}

enum bagSize {

	LargeBag,
	MediumBag,
	SmallBag

}

Should I be trying to move the open bag code to the bad class itself? I’ve made this same style of inventory before without classes so I know what I want to do and roughly how to do it, just need a little push in the right direction.

This line is giving you the error. bagSlots is an int. Your “in” syntax loops through a collection.

for(var a in bagSlotA.bagSlots){

If you just want to loop for bagSlots iterations you can do this:

for (var index = 0; index < bagSlotA.bagSlots; index++)

and get rid of your separate index variable. Note that my syntax may be slightly off since I don’t often use Javascript.

Or you can iterate over the inventorySlots array…

for (var a in inventorySlots)...