Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

Debugging @MisterAtompunk’s monster issue.

@MisterAtompunk was adding a new monster when the old monster died. What happened was an invisible monster was created that hit the player every move. I suspected the issue would be an error with the monster’s position. I added some console.log() statements and I saw this output:

5,4,undefined

The undefined value printed there tells me there is an issue. Two variable are printed: _x and _y and it looks like "5,4" is being set to the first variable, and the second is undefined.

If you look at the makeMonster(x, y) function you can see it accepts two arguments, one for x and one for y, whereas the old code was doing this: makeMonster(Game.alienfort) which can never work because it’s only passing in the one argument (a string with “x,y”).

The fix is to get the x and y values separately out. So I changed his code to this (line 850) and it fixed the issue:

  const pos = posFromKey(Game.alienfort);
  const m = makeMonster(pos[0], pos[1]);

Always check the “arity” of your functions to make sure the arguments going in match what is expected. Using console.log() is a useful way to see if variables hold the value you expect.

Thank you so much for taking the time to look over my mess. Your solution fixed it right up and I am waist deep in alien spawns now! Thank you for all your help and patience.

No worries, great to hear it’s working.