the title name is really self-explanatory
how do you check if you already have an object equipped already
[WUT] AdamLvl 13
- Windows
Can you please provide some code so I can provide a relevant response?
- Windows
You could just make a starter property.
//After creating the sprite
`
sprite.equipped = {
//Change this everytime the player changes to something else
description: 'Name of weapon'
//Add some more properties, like what damage is dealt, recoil, stuff like that
}
if(this.equipped.description === 'weapon you're looking for'){
execute the code
}
`
ASmartCoder i kinda meant like a system of where it can check if you have more than 1 item so that only 1 item can be equipped
[WUT] AdamLvl 13
- Windows
pluto then just make a variable that holds the item you're... well, holding. then, check if the variable is undefined.
basically i just want it so that multiple items cannot be equipped; only one.
- Windows
You could make a big sourcebook variable that would be an object, listing every item and its properties in a subobject. You could then refer to them later.
- Windows
Letti42 Or if the item is a string then do equippedItem = '' to avoid complexities.
Letti42Lvl 6
- Windows
ASmartCoder Null is easier to understand. If anything, making it an empty string would make it even worse
VarrienceLvl 25
- Edited
pluto so you want to do OOP? your post isn't exactly clear on your intentions but i'll assume you want a way of constructing a class. in that case you'll need to setup something like this
var Car = (function() { /** @class */
function Car(name, brand, fuel, mileage, economy) {
this.name = name;
this.brand = brand;
this.fuel = fuel;
this.mileage = milage;
this.fuelEconomy = economy;
}
return Car;
})();
// invoke a class here
var car = new Car("Honda Civic", "Honda", 15, 53429, 30);
personLvl 62
bro got that Honda Civic