+ 2

Basic Shooter Game Problem... Please Help!

I have a bug in my game code, but cannot seem to find the fix to it. Recently I developed a simple shooter mechanism into a fun, little game in which a ninja faces off against zombies (practicing javascript). However, I noticed that while it worked fine from a distance, the moment the zombie was closer than ~100-200 pixels, there is an error, which states "Uncaught TypeError: Cannot read property 'x' of undefined (main: line 46)." My code is written in a javascript framework called p5js. The code is here: https://editor.p5js.org/MattGrim/sketches/BkP-MJe-V To see the error in action, wait until the zombie is close to approaching the character and then move in front of it (w or s) and fire (spacebar). What are the possible syntax/code writing mistakes that would cause this specific error, and what should I look out for? Please help me find the bug. P.S. Next to the main.js title over the code box, there is a > arrow to the left of it. Clicking on that should give you access to all of the files.

29th Dec 2018, 6:17 PM
Matthew Grimalovsky
Matthew Grimalovsky - avatar
4 Answers
+ 2
Basically there is a period where the availability of the enemies is undefined, and so he simply set a case for that (overlapping if statement).
30th Dec 2018, 4:31 AM
Matthew Grimalovsky
Matthew Grimalovsky - avatar
+ 1
Anyone? This is quite urgent and I've been searching for a long time.
29th Dec 2018, 8:07 PM
Matthew Grimalovsky
Matthew Grimalovsky - avatar
+ 1
Thank you so much!
29th Dec 2018, 9:11 PM
Matthew Grimalovsky
Matthew Grimalovsky - avatar
0
What was the answer?
30th Dec 2018, 1:31 AM
James Bartley
James Bartley - avatar