Debug help: issues with sprites, groups and sprite collisions

https://studio.code.org/projects/gamelab/io32yKS6wnVDexNSMruh_nznjSAGL4SRzwlChkUmVeQ <—Link to the project (hope it works)
(arrow keys to move)

Background:
I am developing a top-down SHMUP game to practice working with sprites (prior to now, I never used them, but I am familiar with objects). Currently, I am working on adding enemy types. Two enemy types are ‘implemented’: type 0, which moves in a line periodically and shoots, and type 1, which slowly approaches the player, preparing a pseudo-laser attack. I say implemented in quotes, since type 1 does not fully work.

Problem:
To see this problem, start the project, and with your mouse on the canvas, hold “o” and press “p”.

I managed to work around this problem once, but it comes back to haunt me. After some time (which would be roughly around when it attacks) this error appears within the “update” function:

TypeError: Cannot read properties of null (reading ‘copy’)

In context, lines 374 - 414 are miscellaneous frame updates like collision, hit detection and counters that would look messy in the draw function. 390 specifically is “enemy.collide(player);” which calls for the collide collision mode between the enemy group and the player group (the player controller). If I remove this line (which i intend to do) similar problems arise when it refers to either the enemy group or the “eprojectiles” group, which handles enemy projectiles.

I know that this means that one property of either the sprite summoned is undefined, but this is reusing code from the type 0 enemy, which works. If anyone could bother looking through the code, or tell me how better i could avoid this error, it would be greatly appreciated! :slightly_smiling_face:

@hihattybbc,

This program, although potentially a very fun program is quite out of the intended use of Game Lab as a training tool for Middle and High School students. You are using a lot of non-Game Lab documented javascript, but in doing so, may be pushing the limits of the platform itself. It’s also an older version of Javascript that serves as the base for Game Lab/

I would suggest googling the error. Usually a type error happens if you try to access an integer when it is wanting a string (or any other number of mis-matched data types) and the program can’t figure out what you are trying to access. In this case, the “null” probably means you are trying to access a property that doesn’t exist … but without me spending hours to fully familiarize myself with the game and how you are using the environment, I’m not sure exactly what property it can’t find.

Unfortunately, there aren’t super robust debugging tools in Game Lab to go beyond the basics, but that’s due to it being designed as a training platform for middle & high school students.

There are some “advanced” users on the forum from time to time. If one of them sees this, they may be able to help you. Sorry that we don’t have the time to go through it with a fine tooth comb and help you find the error.

Mike