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



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




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 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
invQt[1] -=1;

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



Thank you very much!



No problem!
I hope you make something cool! :smile:



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

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


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

//Make your inventory array…
//Format of the array is:
var inventory =[



//Loop through your inventory
for(var id =0; id <inventory.length; id++){

//Finds and alerts all inventory items that 
//are of the weap (weapon type.)    
if(inventory[id][0] ==='weap'){alert(inventory[id][1]);}