jburridge Posted January 16, 2014 Share Posted January 16, 2014 (edited) characterBackpackDisplay="Backpack: "+characterBackpack; characterBackpack="emptyyy"; console.log(characterBackpackDisplay); For some reason that first line messes my whole script up, When commented out everything works again. I'm assuming theirs a syntax error? Some more code may help. var randomLoot=loot[Math.floor(Math.random()*loot.length)]; var randomRareLoot=rareLoot[Math.floor(Math.random()*rareLoot.length)]; var randomInteger=Math.random()+11; var randomInteger2=Math.random()+11; function eventMove () { if (randomInteger==randomInteger2) { characterBackpack=characterBackpack+randomRareLoot; } else if (randomInteger==1||5||9) { characterBackpack=characterBackpack+randomLoot; } } Again sorry for the questions, Some things I can't really google because I don't know where I'm going wrong... I don't know why it would break part of my array either? Heres my error ReferenceError: eventMove is not defined world[0][0][0]=eventMove; ReferenceError: characterBackpackDisplay is not defined console.log(characterBackpackDisplay); Edited January 16, 2014 by jburridge Quote Link to comment https://forums.phpfreaks.com/topic/285427-simple-question-again-im-new-to-js/ Share on other sites More sharing options...
kicken Posted January 17, 2014 Share Posted January 17, 2014 (edited) Your variable characterBackpack doesn't exist when the first line is executed so you get an undefined variable error. Swap the order of the lines so you assign characterBackpack first then characterBackpackDisplay second. Your posted errors are similar undefined variable errors but the code you've posted provides no clues as to why. Edited January 17, 2014 by kicken Quote Link to comment https://forums.phpfreaks.com/topic/285427-simple-question-again-im-new-to-js/#findComment-1465507 Share on other sites More sharing options...
jburridge Posted January 17, 2014 Author Share Posted January 17, 2014 (edited) Your variable characterBackpack doesn't exist when the first line is executed so you get an undefined variable error. Swap the order of the lines so you assign characterBackpack first then characterBackpackDisplay second. Your posted errors are similar undefined variable errors but the code you've posted provides no clues as to why. Welp, Thank you for reminding me that they are variables.. I swapped them around and also put "var" in front of them.. No more errors at all. I also changed world[0][0][0]=eventMove; to world[0][0][0]=eventMove(); But... When I move I am still not receiving any "items". I believe their is something wrong with.. movement.js //random loot function var randomLoot=loot[Math.floor(Math.random()*loot.length)]; var randomRareLoot=rareLoot[Math.floor(Math.random()*rareLoot.length)]; var randomInteger=Math.random()+11; var randomInteger2=Math.random()+11; function eventMove () { if (randomInteger==randomInteger2) { characterBackpack=characterBackpack+randomRareLoot; } else if (randomInteger==1||5||9) { characterBackpack=characterBackpack+randomLoot; } } items.js //One-Handed Weapons var infinityBlade="Infinity Blade"; // 4 dmg var crudeSword="Crude Sword"; // 2 dmg //Chest Armor var brokenArmor="Broken Armor"; // 5 health var superiorChestpiece="Superior Chestpiece"; // 10 health var loot=[]; loot[0]=crudeSword; loot[1]=brokenArmor; var rareLoot=[]; rareLoot[0]=infinityBlade; rareLoot[1]=superiorChestpiece; Edited January 17, 2014 by jburridge Quote Link to comment https://forums.phpfreaks.com/topic/285427-simple-question-again-im-new-to-js/#findComment-1465512 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.