Jump to content


Photo

Simple question again, i'm new to js


  • Please log in to reply
2 replies to this topic

#1 jburridge

jburridge

    Member

  • Members
  • PipPip
  • 13 posts

Posted 16 January 2014 - 05:58 PM

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
ReferenceError: characterBackpackDisplay is not defined

Edited by jburridge, 16 January 2014 - 05:58 PM.


#2 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,674 posts
  • LocationBonita, FL

Posted 16 January 2014 - 07:48 PM

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 by kicken, 16 January 2014 - 07:48 PM.

Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#3 jburridge

jburridge

    Member

  • Members
  • PipPip
  • 13 posts

Posted 16 January 2014 - 08:18 PM

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 by jburridge, 16 January 2014 - 08:20 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com