# How to make an item system in a point n' click games?

#1

Hello!

I want to make a point n’ click, but i don’t know how to make an item system

For example, i find a key in a scene and use the key in a door in another scene, then the key disappears from the inventory

If anyone could help me, i would be very grateful

2 Likes

#2

Heyo!

Hmm, personally, I’d go along the lines of this:

//Make two arrays…

//This array will hold the names of the items in inventory.
var invName =[‘Key’,‘Bomb’,‘Torch’,‘M.Glass’];

//While this array holds the quantity the player has of each item.
var invQt =[1,0,3,0];

//If the player finds a key, you would increase the key quantity in
//the inventory like so:
invQt[0] +=1;

/Just in case you, or someone else who’s reading this
doesn’t know how arrays work, basically, if you want to access
a value in an array you created, you call the array, followed by
square brackets. These [ ]. In between the brackets, type in the
number that equates to the parameter of the array that you want
to access. Keep in mind though that arrays are zero-indexed,
meaning, that instead of counting up from one, you start counting
from zero.
/

//For example, using the inventory name array above:
invName =[‘Key’,‘Bomb’,‘Torch’,‘M.Glass’];
//Key’s value is 0, while the value of M.glass is 3.

//Put even more simply:
var invName =[‘0Key’,‘1Bomb’,‘2Torch’,‘3M.Glass’];

//If the player used a bomb, you’d decrease their quantity of bombs
//like:
invQt[1] -=1;

That’s basically it.
If you need anything else, don’t hesitate to ask.

2 Likes

#3

Thank you very much!

2 Likes

#4

No problem!
I hope you make something cool!

2 Likes

#5

You could also make an inventory object instead of an array. That way, you don’t have to memorize the order of the inventory names (for example, `invName[0]` is “Key”).

``````var Inventory = {
key: 1,
bomb: 0,
torch: 3,
magGlass: 0
};
//player finds a key
Inventory.key++;
``````

You could also use the format below if you want to give each item its own properties.

``````var Inventory = {
key: {
qt: 1, //quantity
weapon: false
},
bomb: {
qt: 3,
weapon: true
},
beachBall: {
qt: 2589,
weapon: false,
fun: true
}
};

//check if you have any weapons
var hasWeapons = false;
for (var item in Inventory) { //loop thru all items in inventory
if (Inventory.hasOwnProperty(item)) {
if (Inventory[item].weapon) { //is this a weapon?
hasWeapons = true;
break; //end loop
}
}
}``````
1 Like

#6

Very nice!
As another varient, the same could be done with a two
dimemsional array:

//Format of the array is:
[itemType,itemName,itemQuantity]
var inventory =[

``````['misc','key',1],
['weap','iron_sword',5],
['weap','great_sword',0],
['armr','turtle_armor',1]

];