00:00
00:00
Newgrounds Background Image Theme

Schwicky just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

IndexOf help 2015-03-17 23:19:38


I created an array to hold the names of all the items you can carry in your inventory for my game. I'm trying to make it so that duplicates of items don't show up in your inventory. The string value of the item being added to your inventory should only be added if it doesn't already exist in your bags. I set this up like this.

if(characterClass.itemArray.indexOf(characterClass.ratTeeth) > 1)
					{
						characterClass.ratTeeth +=  3;
					} else {
					characterClass.ratTeeth +=  3;
					characterClass.itemArray.push(characterClass.ratTeethStr);
					trace("Rats Teeth :" , characterClass.ratTeeth);
					updateInv()
					}

If i'm doing something wrong could someone please tell me? Thank you!

Response to IndexOf help 2015-03-18 01:03:00


indexOf returns -1 when a value is not found. You should fix the 'if' condition.

You push 'ratTeethStr' into the array but is checking for 'ratTeeth' so the condition will always return false.


Check out the Flash RPG I made in 2024. It takes about 25 minutes to complete.

BBS Signature