I'm trying to make a simple 'Choose Your Adventure!' game, and I seem to have run into a problem. I don't know how to target certain values of this multi-dimensional array I made. I made a 'dealer/trader' and have his items on sale like this.
var dealer = [
[
{type: "weapon", cost: 250, name: "Claymore"},
{type: "weapon", cost: 75, name: "Dagger"},
{type: "weapon", cost: 350, name: "Magic Staff"},
{type: "weapon", cost: 150, name: "Sword"},
{type: "weapon", cost: 125, name: "Bow"},
{type: "weapon", cost: 125, name: "Crossbow"},
{type: "weapon", cost: 5, name: "Arrow"},
{type: "weapon", cost: 15, name: "Bolt"}
],
[
{type: "clothing", slot: "head", name: "Helmet"},
{type: "clothing", slot: "head", name: "Hood"},
{type: "clothing", slot: "chest", name: "Chestplate"},
{type: "clothing", slot: "chest", name: "Tunic"},
{type: "clothing", slot: "chest", name: "Robe"},
{type: "clothing", slot: "leggings", name: "Legplates"},
{type: "clothing", slot: "leggings", name: "Leggings"},
{type: "clothing", slot: "leggings", slot: "Undergarments"},
{type: "clothing", slot: "feet", name: "Boots"},
{type: "clothing", slot: "feet", name: "Armored Boots"}
]
]
And I have a function that operates the dealer, such as buying an item, I don't know how to target certain values/arrays. This is what I THINK will work.
function merchant() = {
var armor = function(slot, name, material) {
if(dealer[2].slot === "feet" && dealer[2].name = "Boots"}
money -= 10;
}
}
}
That should target the second array of the clothing and look for the slot feet and name of boots, right?
armoris local to the function, how to you intend to call it ?[1]dealerarray (incorrectly) to get (presumably the second) dealer, but that returns another array. To get things in that array you will need to index again. Sodealer[1][8].slot === "feet". But this might be better rearranged as an object keyed off of one of those properties, but it's hard to say without more context.var dealers = [ { name: 'Weapons Dealer', items: [ { type:'weapon', cost: 75, name: 'Dagger' }]}, ... ]