Hello! I’m trying to make a game where enemies have individual health bars assigned to them, however I keep getting an error when I attempt to do so. The code is in the function ‘EnemySetUp’, does anybody know how to fix this?
The code for the snake’s health bar assumes that a snake was created beforehand. However, in Level 2, a snake tile was never found, and so a snake was never created. So, it crashed because it couldn’t get the correct data from an empty variable.
This adds an If statement checking if a snake exists before creating the snake health bars. However, I’d suggest instead is create the health bar inside of the same For loop that creates the snakes. That way, we don’t need to use somewhat odd javascript mechanics, and previous enemies don’t get a snake health bar. (More is in the comment of the added if statement!)
Hope this helps ![]()
I don’t exactly understand what the problem was, but I made 2 new kinds (Snake and Slime) and used these in the code instead. Now it seems to work!
Thank you very much for your help! I’ll try putting the health bar in the for loop.