[SOLVED] First array slot blocking second array slot

Hello everyone,

Am having a weird little issue. In my pause menu I want to display the number of items the character has, but if the number is 0, then I want the item to not appear. so if “Health Potion = 1” 1 health potion would appear in the inventory, but if health potion = 0, then the line disappears. Same goes for bread, (hard tack) water, etc. Things were actually working until I added a second item. (first, if you want to get technical, array slot 1 worked fine, did that first, then went back and added array slot 0. The problem is that array slot 1 seems to be tied to slot 0 somehow, meaning that I can have 10,000 hard tack crackers, but they won’t appear in my inventory guitext until I pick up 1 health potion. (array slot 0) Further, once I’ve picked up a health potion, I can never use the last one, meaning that the player needs 2 or more at all times, and if they have 1, (or less) then they can’t use anything out of slots 0 or 1. I figure it’s an issue with line placement in the code, but thought I’d throw it out to the community while I bang my head against the keyboard. Thanks, and God bless.

//inventory
static var inventoryArray : int[] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var inventoryText : GameObject;
var inventoryText2 : GameObject;
var inventoryText3 : GameObject;
var inventoryText4 : GameObject;
static var PrisonKey : int = 0;
static var TempleKey : int = 0;
static var HealthPotion : int = 0;
static var HardTack : int = 0;
static var Water : int = 0;
static var AppleBrew : int = 0;
//inventoryText.guiText.text = "Health Potion " + "[" + inventoryArray[0] + "]" + "

" + "Hard Tack " + “[” + inventoryArray[1] + “]” + "
" + "Water " + “[” + inventoryArray[2] + “]” + "
" + "Apple Brew " + “[” + inventoryArray[3] + “]” + "
";
function Start () {

inventoryText.guiText.enabled = false;
inventoryText2.guiText.enabled = false;
inventoryText3.guiText.enabled = false;
inventoryText4.guiText.enabled = false;
}

function Update () {



if(inventoryArray[0] > 0) {
inventoryText.guiText.enabled = true;
inventoryText.guiText.text = "Health Potion " + "[" + inventoryArray[0] + "]" + "

";
if(inventoryArray[0] > 0) {
if(Input.GetButtonDown(“Stuff”))
healthPotion();
}

if(inventoryArray[1] > 0) {
inventoryText2.guiText.enabled = true;
inventoryText2.guiText.text = "Hard Tack " + "[" + inventoryArray[1] + "]" + "

";
if(inventoryArray[1] > 0) {
if(Input.GetButtonDown(“Sword Slash”))
hardTack();
}
if(Input.GetButtonDown(“Jump”))

if(Water > 0) {

water();
}
}
}
}

function healthPotion ()  {

Playerhealth.curHealth += 15;
inventoryArray[0] -=1;
HealthPotion -=1;
}

function hardTack ()  {

Playerhunger.curHunger -= 5;
inventoryArray[1] -=1;
HardTack -=1;

if(inventoryArray[1] == 0) {
inventoryText2.guiText.enabled = false;
}
}

function water ()  {

Playerthirst.curThirst -= 100;
Water -=1;
}

Item Pick up Script (Health Potion)

var    chestSound : AudioClip; 
var treasureChest : GameObject; 
 
function OnTriggerEnter (col : Collider) {
 
if(col.gameObject.tag == "Player") { 
Inventory.inventoryArray[0]++;
Inventory.HealthPotion++;
AudioSource.PlayClipAtPoint(chestSound, transform.position); 
treasureChest.animation.Play(); 
Destroy(gameObject);
 
 
}
}

Your code is not so well indented but I feel your second check, the one for inventory[1] is within the first which makes sense why you need one potion to see your crackers.

The reason why you cannot use the last one in your inventory is because you use:

 if(inventoryArray[0] > 0) 

and the Input is inside of that. To use down to 0 you need:

if(inventoryArray[0] >= 0) 

By the way since you have all items as variables, there is no real need for the array.
You should pick one or the other.