Hello everyone,
Long time lurker, first time poster. I'm a beginner coder, and I've taught myself everything with the help and expertise of users and websites like this one. I normally figure out any problem, but this one really has me stumped.
Basically, I have created a site that initially loads a set of "items" and their values into 17 drop down menus from an XML file. Each of those "items" when selected from the drop down menu loads data into a few arrays, and outputs it to a table. The data is then used for a calculation output, which is the overall goal of the program/site.
Everything works fine up to this point...
Now I'm introducing a button that automatically selects the 17 "items." So basically my application runs through a loop and is supposed to: select each item, load each XML file, interprets each "items" data, save each "item" data to arrays, and then outputs each to the table.
It works fine locally with internet explorer 6, but does not work with Firefox online/local, or IE online. If I add an "alert" somewhere in the loop process, it works, but then I have 17 alerts to deal with. IE online only inputs the last item in the table, and Firefox outputs all 0's locally, and then online Firefox implements mostly all zeros, except for the last and first(which outputs the data of the last instead of the first).
So anyway, my source code is about 2000 lines. You can access my program at http://www.stasistech.com/wow/test/itemdps.html (click the max "i.lvl" button to see the problem)
js: http://www.stasistech.com/wow/test/itemdps.js
Here's the code that somewhere has the problem(i hope!):
[code=javascript]
itemSlots=new Array();
itemSlots[0]="head";
itemSlots[1]="shoulders" ;
...
itemSlots[16]="relic";
//called by the button to select gear
function selectGear(gear )
{
switch(gear)
{
case "lvl":
for (j0=0; j0<itemSlots.le ngth; j0++)
{
document.itemFo rm.elements[itemSlots[j0]].selectedIndex = 1;
loadItem(docume nt.itemForm.ele ments[itemSlots[j0]],itemSlots[j0])
}
break;
}
}
//loads each item, ignore the unlock step
function loadItem(itemID ,slot)
{
//special flag called by selecting the last item
unlockItemFlag= 0;
//unlocks slot with user input
if(itemID.optio ns[itemID.selected Index].value =="7")unlockSlo t(slot);
if(unlockItemFl ag==0)lockSlot( slot);
//loads file for each item
var xmlFileLocation = ('items/'+itemID.option s[itemID.selected Index].value + '.xml')
loadXML(xmlFile Location,1,slot );
}
//XML Loading
function loadXML(xmlFile ,type,slot)
{
if (detectBrowser( )=="IE")
{
xmlDoc = new ActiveXObject(" Microsoft.XMLDO M");
xmlDoc.onreadys tatechange = function ()
{
if (xmlDoc.readySt ate == 4)
{
switch(type)
{
case 0:
for(k=0; k<itemSlots.len gth; k++)
{
loadItemsIntoMe nus(itemSlots[k]);
}
break;
case 1:
loadItemStats(s lot,xmlDoc);
break;
case 2:
fillBox();
break;
}
}
};
xmlObj=xmlDoc.d ocumentElement;
}
else if (detectBrowser( )=="FF")
{
xmlDoc = document.implem entation.create Document("", "", null);
xmlDoc.load(xml File);
xmlDoc.onload=f unction()
{
switch(type)
{
case 0:
for(k=0; k<itemSlots.len gth; k++)
{
loadItemsIntoMe nus(itemSlots[k]);
}
break;
case 1:
loadItemStats(s lot,xmlDoc);
break;
case 2:
fillBox();
break;
}
};
}
else
{
alert("you can't handle this script! please use firefox or internet explorer")
}
xmlDoc.load(xml File);
}
//disregard the massive quantity of XML interpretations
function loadItemStats(s lot,xmlDoc)
{
//clearItemValues (slot);
slotNum=slotTex tToNum(slot);
//reset item to zeros
relicManaReduct ion=0;
itemCrit[slotNum]=0;
itemHit[slotNum]=0;
itemInt[slotNum]=0;
itemStam[slotNum]=0;
itemDmg[slotNum]=0;
itemMp5[slotNum]=0;
itemHaste[slotNum]=0;
socketNumber=0;
if(slot=="head" )metaFlag=0;
socketFlag=0;
//check for sockets
if (xmlDoc.getElem entsByTagName(' socket') != null)
{
var socketInfo = xmlDoc.getEleme ntsByTagName('s ocket');
for (k5=0; k5<socketInfo.l ength; k5++)
{
socketFlag=1;
socketColors[k5]=socketInfo[k5].getAttribute(" color")
if (socketColors[k5]== "Meta")
{
metaFlag=1;
}
socketNumber=k5 +1;
//unlocks gems
document.itemFo rm.elements[slot+"Gem"+sock etNumber].disabled=false ;
}
//lock out and disable empty sockets
for (socketsEmpty=k 5+1; socketsEmpty <=3; socketsEmpty++)
{
if(unlockItemFl ag==0)document. itemForm.elemen ts[slot+"Gem"+sock etsEmpty].disabled=true;
}
}
newGemLoader(sl ot);
// alert(xmlDoc.ge tElementsByTagN ame("bonusIntel lect").item(0). firstChild.data )
//check for int
if (xmlDoc.getElem entsByTagName(" bonusIntellect" ).item(0) != null)
{
itemInt[slotNum]=xmlDoc.getElem entsByTagName(" bonusIntellect" ).item(0).first Child.data*1;
}
//check for stam
if (xmlDoc.getElem entsByTagName(" bonusStamina"). item(0) != null)
{
itemStam[slotNum]=xmlDoc.getElem entsByTagName(" bonusStamina"). item(0).firstCh ild.data*1;
}
//check for crit
if (xmlDoc.getElem entsByTagName(" bonusCritSpellR ating").item(0) != null)
{
itemCrit[slotNum]=xmlDoc.getElem entsByTagName(" bonusCritSpellR ating").item(0) .firstChild.dat a*1;
}
//check for hit
if (xmlDoc.getElem entsByTagName(" bonusHitSpellRa ting").item(0) != null)
{
itemHit[slotNum]=xmlDoc.getElem entsByTagName(" bonusHitSpellRa ting").item(0). firstChild.data *1;
}
//check for haste
if (xmlDoc.getElem entsByTagName(" bonusHasteSpell Rating").item(0 ) != null)
{
itemHaste[slotNum]=xmlDoc.getElem entsByTagName(" bonusHasteSpell Rating").item(0 ).firstChild.da ta*1;
}
//itemDamage[slot]=xmlDoc.getElem entsByTagName(" spellData").ite m(1).firstChild .data)
for (k=0; xmlDoc.getEleme ntsByTagName('d esc')[k] != null; k++)
{
//alert(xmlDoc.ge tElementsByTagN ame('desc')[k].lastChild.data );
itemData=xmlDoc .getElementsByT agName('desc')[k].lastChild.data
//Check for +Damage
if (itemData.match ("Increases damage and healing done by magical spells and effects by up to"))
{
itemDmg[slotNum]=parseFloat(ite mData.substring (itemData.lengt h-4,itemData.leng th-1));
}
//Check for Mana Regen
else if (itemData.match ("Restores "))
{
itemMp5[slotNum]=parseFloat(ite mData.substring (9,12));
}
//check for LB/CL dmg
else if(itemData.mat ch("Increases damage done by Chain Lightning and Lightning Bolt by up to "))
{
itemDmg[slotNum]=parseFloat(ite mData.substring (itemData.lengt h-3,itemData.leng th-1));
}
else if(itemData.mat ch("Reduces the mana cost of") && itemData.match( "Lightning" ))
{
relicManaReduct ion=parseFloat( itemData.substr ing(itemData.le ngth-3,itemData.leng th-1));
}
else
{
}
}
calculateItemSt ats(slot,slotNu m);
outputItemStats (slot,slotNum);
// alert("int:\t" + itemInt[slotNum]+"\n\nstam:\ t" + itemStam[slotNum] + "\n\ncrit:\ t" + itemCrit[slotNum] + "\n\ndamage :\t" + itemDmg[slotNum] + "\n\nregen: \t" + itemMp5[slotNum])
}
function calculateItemSt ats(slot,slotNu m)
{
totalItemStam[slotNum]=itemStam[slotNum]+itemEnchantSta m[slotNum]+itemGem1Stam[slotNum]+itemGem2Stam[slotNum]+itemGem3Stam[slotNum];
totalItemInt[slotNum]=itemInt[slotNum]+itemEnchantInt[slotNum]+itemGem1Int[slotNum]+itemGem2Int[slotNum]+itemGem3Int[slotNum];
totalItemDmg[slotNum]=itemDmg[slotNum]+itemEnchantDmg[slotNum]+itemGem1Dmg[slotNum]+itemGem2Dmg[slotNum]+itemGem3Dmg[slotNum];
totalItemCrit[slotNum]=itemCrit[slotNum]+itemEnchantCri t[slotNum]+itemGem1Crit[slotNum]+itemGem2Crit[slotNum]+itemGem3Crit[slotNum];
totalItemHit[slotNum]=itemHit[slotNum]+itemEnchantHit[slotNum]+itemGem1Hit[slotNum]+itemGem2Hit[slotNum]+itemGem3Hit[slotNum];
totalItemMp5[slotNum]=itemMp5[slotNum]+itemEnchantMp5[slotNum]+itemGem1Mp5[slotNum]+itemGem2Mp5[slotNum]+itemGem3Mp5[slotNum];
totalItemHaste[slotNum]=itemHaste[slotNum]+itemEnchantHas te[slotNum]+itemGem1Haste[slotNum]+itemGem2Haste[slotNum]+itemGem3Haste[slotNum];
}
function outputItemStats (slot,slotNum)
{
document.itemFo rm.elements[slot+"Stam"].value=totalIte mStam[slotNum];
document.itemFo rm.elements[slot+"Int"].value=totalIte mInt[slotNum];
document.itemFo rm.elements[slot+"Dmg"].value=totalIte mDmg[slotNum];
document.itemFo rm.elements[slot+"Crit"].value=totalIte mCrit[slotNum];
document.itemFo rm.elements[slot+"Hit"].value=totalIte mHit[slotNum];
document.itemFo rm.elements[slot+"Mp5"].value=totalIte mMp5[slotNum];
document.itemFo rm.elements[slot+"Haste"].value=totalIte mHaste[slotNum];
}
[/code]
Thanks in advance for your help,
-Rob
Long time lurker, first time poster. I'm a beginner coder, and I've taught myself everything with the help and expertise of users and websites like this one. I normally figure out any problem, but this one really has me stumped.
Basically, I have created a site that initially loads a set of "items" and their values into 17 drop down menus from an XML file. Each of those "items" when selected from the drop down menu loads data into a few arrays, and outputs it to a table. The data is then used for a calculation output, which is the overall goal of the program/site.
Everything works fine up to this point...
Now I'm introducing a button that automatically selects the 17 "items." So basically my application runs through a loop and is supposed to: select each item, load each XML file, interprets each "items" data, save each "item" data to arrays, and then outputs each to the table.
It works fine locally with internet explorer 6, but does not work with Firefox online/local, or IE online. If I add an "alert" somewhere in the loop process, it works, but then I have 17 alerts to deal with. IE online only inputs the last item in the table, and Firefox outputs all 0's locally, and then online Firefox implements mostly all zeros, except for the last and first(which outputs the data of the last instead of the first).
So anyway, my source code is about 2000 lines. You can access my program at http://www.stasistech.com/wow/test/itemdps.html (click the max "i.lvl" button to see the problem)
js: http://www.stasistech.com/wow/test/itemdps.js
Here's the code that somewhere has the problem(i hope!):
[code=javascript]
itemSlots=new Array();
itemSlots[0]="head";
itemSlots[1]="shoulders" ;
...
itemSlots[16]="relic";
//called by the button to select gear
function selectGear(gear )
{
switch(gear)
{
case "lvl":
for (j0=0; j0<itemSlots.le ngth; j0++)
{
document.itemFo rm.elements[itemSlots[j0]].selectedIndex = 1;
loadItem(docume nt.itemForm.ele ments[itemSlots[j0]],itemSlots[j0])
}
break;
}
}
//loads each item, ignore the unlock step
function loadItem(itemID ,slot)
{
//special flag called by selecting the last item
unlockItemFlag= 0;
//unlocks slot with user input
if(itemID.optio ns[itemID.selected Index].value =="7")unlockSlo t(slot);
if(unlockItemFl ag==0)lockSlot( slot);
//loads file for each item
var xmlFileLocation = ('items/'+itemID.option s[itemID.selected Index].value + '.xml')
loadXML(xmlFile Location,1,slot );
}
//XML Loading
function loadXML(xmlFile ,type,slot)
{
if (detectBrowser( )=="IE")
{
xmlDoc = new ActiveXObject(" Microsoft.XMLDO M");
xmlDoc.onreadys tatechange = function ()
{
if (xmlDoc.readySt ate == 4)
{
switch(type)
{
case 0:
for(k=0; k<itemSlots.len gth; k++)
{
loadItemsIntoMe nus(itemSlots[k]);
}
break;
case 1:
loadItemStats(s lot,xmlDoc);
break;
case 2:
fillBox();
break;
}
}
};
xmlObj=xmlDoc.d ocumentElement;
}
else if (detectBrowser( )=="FF")
{
xmlDoc = document.implem entation.create Document("", "", null);
xmlDoc.load(xml File);
xmlDoc.onload=f unction()
{
switch(type)
{
case 0:
for(k=0; k<itemSlots.len gth; k++)
{
loadItemsIntoMe nus(itemSlots[k]);
}
break;
case 1:
loadItemStats(s lot,xmlDoc);
break;
case 2:
fillBox();
break;
}
};
}
else
{
alert("you can't handle this script! please use firefox or internet explorer")
}
xmlDoc.load(xml File);
}
//disregard the massive quantity of XML interpretations
function loadItemStats(s lot,xmlDoc)
{
//clearItemValues (slot);
slotNum=slotTex tToNum(slot);
//reset item to zeros
relicManaReduct ion=0;
itemCrit[slotNum]=0;
itemHit[slotNum]=0;
itemInt[slotNum]=0;
itemStam[slotNum]=0;
itemDmg[slotNum]=0;
itemMp5[slotNum]=0;
itemHaste[slotNum]=0;
socketNumber=0;
if(slot=="head" )metaFlag=0;
socketFlag=0;
//check for sockets
if (xmlDoc.getElem entsByTagName(' socket') != null)
{
var socketInfo = xmlDoc.getEleme ntsByTagName('s ocket');
for (k5=0; k5<socketInfo.l ength; k5++)
{
socketFlag=1;
socketColors[k5]=socketInfo[k5].getAttribute(" color")
if (socketColors[k5]== "Meta")
{
metaFlag=1;
}
socketNumber=k5 +1;
//unlocks gems
document.itemFo rm.elements[slot+"Gem"+sock etNumber].disabled=false ;
}
//lock out and disable empty sockets
for (socketsEmpty=k 5+1; socketsEmpty <=3; socketsEmpty++)
{
if(unlockItemFl ag==0)document. itemForm.elemen ts[slot+"Gem"+sock etsEmpty].disabled=true;
}
}
newGemLoader(sl ot);
// alert(xmlDoc.ge tElementsByTagN ame("bonusIntel lect").item(0). firstChild.data )
//check for int
if (xmlDoc.getElem entsByTagName(" bonusIntellect" ).item(0) != null)
{
itemInt[slotNum]=xmlDoc.getElem entsByTagName(" bonusIntellect" ).item(0).first Child.data*1;
}
//check for stam
if (xmlDoc.getElem entsByTagName(" bonusStamina"). item(0) != null)
{
itemStam[slotNum]=xmlDoc.getElem entsByTagName(" bonusStamina"). item(0).firstCh ild.data*1;
}
//check for crit
if (xmlDoc.getElem entsByTagName(" bonusCritSpellR ating").item(0) != null)
{
itemCrit[slotNum]=xmlDoc.getElem entsByTagName(" bonusCritSpellR ating").item(0) .firstChild.dat a*1;
}
//check for hit
if (xmlDoc.getElem entsByTagName(" bonusHitSpellRa ting").item(0) != null)
{
itemHit[slotNum]=xmlDoc.getElem entsByTagName(" bonusHitSpellRa ting").item(0). firstChild.data *1;
}
//check for haste
if (xmlDoc.getElem entsByTagName(" bonusHasteSpell Rating").item(0 ) != null)
{
itemHaste[slotNum]=xmlDoc.getElem entsByTagName(" bonusHasteSpell Rating").item(0 ).firstChild.da ta*1;
}
//itemDamage[slot]=xmlDoc.getElem entsByTagName(" spellData").ite m(1).firstChild .data)
for (k=0; xmlDoc.getEleme ntsByTagName('d esc')[k] != null; k++)
{
//alert(xmlDoc.ge tElementsByTagN ame('desc')[k].lastChild.data );
itemData=xmlDoc .getElementsByT agName('desc')[k].lastChild.data
//Check for +Damage
if (itemData.match ("Increases damage and healing done by magical spells and effects by up to"))
{
itemDmg[slotNum]=parseFloat(ite mData.substring (itemData.lengt h-4,itemData.leng th-1));
}
//Check for Mana Regen
else if (itemData.match ("Restores "))
{
itemMp5[slotNum]=parseFloat(ite mData.substring (9,12));
}
//check for LB/CL dmg
else if(itemData.mat ch("Increases damage done by Chain Lightning and Lightning Bolt by up to "))
{
itemDmg[slotNum]=parseFloat(ite mData.substring (itemData.lengt h-3,itemData.leng th-1));
}
else if(itemData.mat ch("Reduces the mana cost of") && itemData.match( "Lightning" ))
{
relicManaReduct ion=parseFloat( itemData.substr ing(itemData.le ngth-3,itemData.leng th-1));
}
else
{
}
}
calculateItemSt ats(slot,slotNu m);
outputItemStats (slot,slotNum);
// alert("int:\t" + itemInt[slotNum]+"\n\nstam:\ t" + itemStam[slotNum] + "\n\ncrit:\ t" + itemCrit[slotNum] + "\n\ndamage :\t" + itemDmg[slotNum] + "\n\nregen: \t" + itemMp5[slotNum])
}
function calculateItemSt ats(slot,slotNu m)
{
totalItemStam[slotNum]=itemStam[slotNum]+itemEnchantSta m[slotNum]+itemGem1Stam[slotNum]+itemGem2Stam[slotNum]+itemGem3Stam[slotNum];
totalItemInt[slotNum]=itemInt[slotNum]+itemEnchantInt[slotNum]+itemGem1Int[slotNum]+itemGem2Int[slotNum]+itemGem3Int[slotNum];
totalItemDmg[slotNum]=itemDmg[slotNum]+itemEnchantDmg[slotNum]+itemGem1Dmg[slotNum]+itemGem2Dmg[slotNum]+itemGem3Dmg[slotNum];
totalItemCrit[slotNum]=itemCrit[slotNum]+itemEnchantCri t[slotNum]+itemGem1Crit[slotNum]+itemGem2Crit[slotNum]+itemGem3Crit[slotNum];
totalItemHit[slotNum]=itemHit[slotNum]+itemEnchantHit[slotNum]+itemGem1Hit[slotNum]+itemGem2Hit[slotNum]+itemGem3Hit[slotNum];
totalItemMp5[slotNum]=itemMp5[slotNum]+itemEnchantMp5[slotNum]+itemGem1Mp5[slotNum]+itemGem2Mp5[slotNum]+itemGem3Mp5[slotNum];
totalItemHaste[slotNum]=itemHaste[slotNum]+itemEnchantHas te[slotNum]+itemGem1Haste[slotNum]+itemGem2Haste[slotNum]+itemGem3Haste[slotNum];
}
function outputItemStats (slot,slotNum)
{
document.itemFo rm.elements[slot+"Stam"].value=totalIte mStam[slotNum];
document.itemFo rm.elements[slot+"Int"].value=totalIte mInt[slotNum];
document.itemFo rm.elements[slot+"Dmg"].value=totalIte mDmg[slotNum];
document.itemFo rm.elements[slot+"Crit"].value=totalIte mCrit[slotNum];
document.itemFo rm.elements[slot+"Hit"].value=totalIte mHit[slotNum];
document.itemFo rm.elements[slot+"Mp5"].value=totalIte mMp5[slotNum];
document.itemFo rm.elements[slot+"Haste"].value=totalIte mHaste[slotNum];
}
[/code]
Thanks in advance for your help,
-Rob
Comment