I've some code for an object constructor of the form:
function objectConstructor(item, r) {
//Pulls a string from elsewhere
this.name = Object.ObjectOne[item].name;
this.amount = Object.ObjectOne[item].amount;
this.buttonID = pickButton(r);
this.itemInitialCost = [];
this.itemPriceIncrease = [];
//This is the problematic area.
if (this.name != "valueOne" || this.name != "valueTwo" || this.name != "valueThree" || this.name != "valueFour" || [...]) {
for (var i = 0; i < Object.ObjectTwo[this.buttonID].cost.length; i++) {
this.itemInitialCost.push(Object.ObjectTwo[this.buttonID].cost[i].initialCost; this.itemPriceIncrease.push(Object.ObjectTwo[this.buttonID].cost[i].costIncrease;
}
}
else{
this.itemInitialCost.push("none");
this.itemPriceIncrase.push("none");
}
}
function pickButton(r){
//The Function
}
var array = [Long List]
for (var i = 0; i < array.length; i++){
item = array[i];
items[item] = new objectConstructor(item, i)
console.log("Created: " + item);
}
console.log(items);
The first 58 (of 67) item objects are created and assigned values just fine. All items after the 58th don't have a buttonID, and therefore would throw errors when they tried to get their cost values. To prevent this, I've the if statement set to assign those items (based on the item name) the value of "none" for cost. However, they seem to be ignoring the conditions in the if statement and going straight to the for loop that would set a normal items costs. They aren't going to the else statement, and are thereby causing my script to crash. Why are they, apparently, ignoring the if statement's conditions?
EDIT: Sorry for the messed up snippet formatting. I've never used this site's text editor before, and it seems to ignore some of the spacing I used.
Aucun commentaire:
Enregistrer un commentaire