DrSnuggles

Members
  • Content Count

    6
  • Joined

  • Last visited

  • Days Won

    1

DrSnuggles last won the day on May 1

DrSnuggles had the most liked content!

About DrSnuggles

  • Rank
    Newbie
  1. Good that you bumped it. Have a look here: https://github.com/DrSnuggles/Decruncher/tree/ldr This was first intended for showing the decrunching process in Amiga style but then i made this branch to also show the loading process. The display is not a fancy spinner more a oldskool interlace lined data display but it's canvas and should help you.
  2. yes, init of the new object in the array is important. It's important because later you want to access gear.something and gear has not yet been created. That's where the error is coming from. JS can not DIM an array from begin like it is possible in other languages. You can DIM with var myArray = new Array(20) but this just creates empty entries and not objects, so you cant set the property "cost". Have look here: https://www.w3schools.com/js/js_arrays.asp var myArray = []; Dim(myArray, 20); // maybe you like this more than the for i=0;i<myArray.length;i++ loop for (key in myArray) { myArray[key].cost = 20; } // another way to fill it myArray.forEach(setDmg); console.log(myArray); // shows filled array function Dim(arr, size) { for (let i = 0; i < size; i++) { myArray.push({}); } } function setDmg(entry) { entry.dmg = 10; } Working with the good old arrays is absolute no problem and a clean way to do that. Try to make it easy for you to understand that code again if you dig it out in some years.
  3. [] = array {} = object That's right and important this here works. I'm doing hard finding the prb without weaponsList. var weapons = [ { name: "Knife", rank: { damagePerClk: 2, cost: 1, }, }, { name: "BFG", rank: { damagePerClk: 9999, cost: 500, }, }, ]; for (var i = 0; i < weapons.length; i++) { console.log("Name: "+ weapons[i].name); console.log("damagePerClk: "+ weapons[i].rank.damagePerClk); console.log("Cost: "+ weapons[i].rank.cost); } it looks like you want to init your weapons in the initGame function. several way to do that. var weapon = []; var weaponList = ['Knife', 'BFG']; var spell = ['Light', 'Fireball']; function initGame() { var wLength = weaponList.length; var sLength = spell.length; for(let i = 0; i < wLength; i++) { weapon[i] = {}; // this is important, creates an object in weapon array weapon[i].name = weaponList[i]; //spell[i].name = spellList[i]; console.log(weapon[i].name); } } function initGame2() { var wLength = weaponList.length; var sLength = spell.length; for(let i = 0; i < wLength; i++) { // push the full object weapon.push({ name: weaponList[i], anotherKey: 0.666} ); console.log(weapon[i].name); } } function initGame3() { var wLength = weaponList.length; var sLength = spell.length; for(let i = 0; i < wLength; i++) { var tmp = {}; tmp.name = weaponList[i]; tmp.foo = "bar"; weapon.push( tmp ); console.log(weapon[i].name); } } hope this helps you.
  4. another way is to make the 3rd layer an object. Sometimes it's nicer to access them by names = Object.keys var mobxCnt = 100; var currwavecnt = 80; var setHP = 100; var setSpeed = 0.3; var Mob = []; for (var i = 0; i < mobxCnt; i++) { for (var j = 0; j < currwavecnt; j++) { if (j === 0) { Mob = []; // init 2nd dimension of array } Mob[j] = {}; // init object as 3rd "layer" Mob[j].hp = setHP; Mob[j].speed = setSpeed; } } // access console.log('Health: '+ Mob[42][23].hp); console.log('Speed: '+ Mob[42][23].speed);
  5. sure you want to stick to array? Object could also be an option. requested Array JS var mobxCnt = 100; var currwavecnt = 80; var Mob = []; // init 1st dimension of array for (var i = 0; i < mobxCnt; i++) { for (var j = 0; j < currwavecnt; j++) { if (j === 0) { Mob = []; // init 2nd dimension of array } Mob[j] = 100; // set hp } } // access console.log('Health: '+ Mob[42][23]); --------------------- if you want more then just hp var mobxCnt = 100; var currwavecnt = 80; var setHP = 100; var setSpeed = 0.3; var Mob = []; // init 1st dimension of array for (var i = 0; i < mobxCnt; i++) { for (var j = 0; j < currwavecnt; j++) { if (j === 0) { Mob = []; // init 2nd dimension of array } Mob[j] = [setHP, setSpeed]; // set hp and speed as single vals in an array } } // access console.log('Health: '+ Mob[42][23][0]); console.log('Speed: '+ Mob[42][23][1]);
  6. Nice to play because it has nice Audio+Video but think its quite hard. Would love to see a damage meter or taxi gauge instead of instant replay level.