Jump to content

Simple question again, i'm new to js


jburridge

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.