• Question
  • Any way to make some sort of shop system with arrays (gamelab)

so i want to yk make a shopping system, as i dont want to make more variables then needed, i'm using arrays for a somewhat less time consuming approach.

i have tried to use includes(), but as far as I know it for some reason doesn't work for arrays.

here is an example of what im trying to do so you can base it off mine.

var list = ["a", "b", "c"] //then i need something to check if for example if it has "a"

theres only like 2 that works because this is es5
they also turn in to true or false
oh yeah and stupid me forgot to call the function for the shop to work; resolved

there's already hundreds of forums online that will give you this answer, I'm sure it's been asked on StackOverflow a thousand times by now.

and most of your questions have already been answered somewhere online... try and use google or stackoverflow next time you're wondering something or have a question

im pretty sure this is a bit too over the top as i know there has to be something to shorten it as i will have to repeat this for each item, this will be a massive line waste

if (mouseIsOver(gogglesBtnP1) && mouseWentDown("leftButton") && itemsP1[0] == "" && eggbucksP1 >= 500) {
setTimeout(function() {
itemsP1[0] = "goggles";
}, 50);
eggbucksP1 -= 500;
}
if (mouseIsOver(gogglesBtnP1) && mouseWentDown("leftButton") && itemsP1[0] == "goggles") {
setTimeout(function() {
itemsP1[0] = "gogglesEquipped";
}, 50);
}
if (mouseIsOver(gogglesBtnP1) && mouseWentDown("leftButton") && itemsP1[0] == "gogglesEquipped") {
setTimeout(function() {
itemsP1[0] = "goggles";
}, 50);
}
if (itemsP1[0] == "") {
text("Buy", 48, 94);
}
if (itemsP1[0] == "goggles") {
gogglesBtnP1.setAnimation("equipBtn");
text("Equip", 42, 94);
}
if (itemsP1[0] == "gogglesEquipped") {
gogglesBtnP1.setAnimation("equipBtn");
textSize(12);
text("Unequip", 37, 93);
}

Chat