Count Variable Acting Strange

CODE:

public void InventoryWindow(int id){
		int cnt = 0;
		string itemToolTip;						
		for(int y = 0; y < _inventoryRows; y++){
			for(int x = 0; x < _inventoryCols; x++){
				if(cnt < inv.Stacks.Count && inv.Stacks[cnt] != null){
					if(!editing){
						itemToolTip =  "<b>" + inv.Stacks[cnt].Item.Name + "</b> 

" + inv.Stacks[cnt].Item.Description + "
<size=10>" + inv.Stacks[cnt].Item.Type + “”;
} else{itemToolTip = “”;}
if(GUI.Button(new Rect(5 + (x * buttonWidth), 20 + (y * buttonHeight), buttonWidth, buttonHeight), new GUIContent(inv.Stacks[cnt].Item.Icon, itemToolTip), “box”)){
editing = true;
}
if(editing){
GUI.BeginGroup(new Rect(32.5f, 280, 200, 90), comboBacker);
for(int i = 0 ; i < items.Length; i++){
int index = cnt;
print(cnt + " = Index!“);//Normal here********
if(GUI.Button(new Rect(0, (30 * i), 200, 30), items*, “button”)){*
_ print(cnt + " = COUNT!!!”);//Always Zero here********_
_ selectedItem = items*;_
_
editing = false;_
_
switch(selectedItem){_
_
case “Use”:_
_
//print (“Use Item”);//Use Item*_
* UseItem(inv.Stacks[index].Item);*
* break;*
* case “Drop”:*
* //print (“Drop Item”);//Drop Item*
* break;*
* case “Cancel”:*
* //Do nothing, just close options*
* break;*
* default:*
* //Do nothing, just close options*
* break;*
* }*
* }*
* }*
* GUI.EndGroup();*
* }*

_ GUI.Label(new Rect(6 + (x * buttonWidth), 20 + (y * buttonHeight), 50, 50), inv.Stacks[cnt].Size.ToString(), “label”);_
* //print (inv.Stacks[cnt].Item.Name);*

* } else if(inv.Stacks[cnt] == null){*
GUI.Button(new Rect(5 + (x * buttonWidth), 20 + (y * buttonHeight), buttonWidth, buttonHeight), (x + y * inventoryCols).ToString(), “box”);
* }*
* //print(cnt);*
* cnt++;*
* }*
* }*
* Tooltip.Instance.TooltipGUI();*
* GUI.DragWindow();*
* }*
For some reason when i try to reference the ‘cnt’ variable at the switch statement it always equals ZERO?
About 4/5 lines from bottom i have a print which is working fine and the ‘cnt’ variales is working, but why not for the switch statement?
EDIT:
The ‘cnt’ variable stops working after line 18, but works fine before it.
*Added Whole Function_

OK, i have worked out the silly problem :stuck_out_tongue:

It was because i was using ‘cnt’ to reference the item which was ever changing while the user selected a drop down box option(Dunno why it was always 0 though?), so when the userclicked on the inventoryitem i needed to store the current index to stop it changing.

Thanks anyway :stuck_out_tongue: