Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Hehe! Puns!

Woo! Devlog! Code!

Could avoid "enemy" variable by using a map for a "get level" code, then sum the array?

https://www.w3schools.com/jsref/jsref_map.asp

Now that I think on it, the cancel cost in Trail of the Interloper and Heaven’s Gate was based on a note-tag on the map! I just happen to set that note-tag to be the approximate average level of the possible encounters of the map.

That aside, the map() function of arrays might not have been one I’m familiar with, but, it does seem worth looking into.

(1 edit) (+1)

I’ve spend a number of hours playing with map(). I can’t see how I can avoid using an enemy variable simply because of how enemy levels are stored/obtained with the enemy level plugin I’ve made/got.

For a bit more in depth discussion, I was also looking into the forEach() function of arrays as well, and the combination of map and forEach seemed somewhat promising. Could I use them as a kind of loop function to get the summation of levels that way?

This was apparently not the case. The debug console reported the correct numbers being passed into the function, but the end result that the variable actually stored was undefined. The only sense I can make of that is that I was using an assignment function…

  // Stuff above this is whatever.
  let troop = $dataTroops[this.troopId];
  let total = 0;
  let levelArray = troop.members.map(id => this.levelArray(id));
  let temp = levelArray.forEach(val => levelSum(val));
  console.log(temp);
  // Skipping more code-block.

Game_Enemy.prototype.levelArray = function(id) {
  let enemy = new Game_Enemy(troop.members[id].enemyId, 0, 0);
  return enemy.level;
};

Game_Enemy.prototype.levelSum = function(val) {
  console.log(val);
  return val += val;
};

…and maybe that’s not the proper use of the forEach function. Maybe there is another way I could do this, but, I’m currently on the “if it isn’t bork, don’t fix” headspace at this moment!

Ah well. Yep, it's only one call / variable. It shouldn't lag on any target machine!