Search code examples
actionscript-3flashdevelop2d-games

Flashdevelop As3 src\Enemy.as(28): col: 16 Error: Return value must be undefined. return false;


I am currently working on a game for my uni module and can't seem figure out how to solve this problem. Can someone please help me? The game is a 2D Platformer and I am trying to make the Enemy dissapear when the health of the enemy is <=0, but I get these Error messages when I try to test the game. D:\FlashDevelop\Projects\Assessment (Game Techniques)\src\Enemy.as(27): col: 16 Error: Return value must be undefined. return true; ^ D:\FlashDevelop\Projects\Assessment (Game Techniques)\src\Enemy.as(28): col: 16 Error: Return value must be undefined. return false; ^ Build halted with errors (fcsh).

this is my code for the enemy:

package  
{
    import flash.display.MovieClip;
    /**
     * ...
     * @author Umeer
     */
    public class Enemy extends MovieClip
    {
        public var health:int = 100;
        public function Enemy() 
        {
            this.graphics.beginFill(0xFF1100, 1);
            this.graphics.drawCircle(this.x, this.y, 25);
            this.graphics.endFill();
        }
        public function CheckObj(obj:Player,bullets:Array):void
        {
            if (Math.abs(obj.x - x) < obj.width / 2 + width / 2 && Math.abs(obj.y - y) < obj.height / 2 + height / 2)
                obj.health --;
            for (var i:int = 0; i < bullets.length; i++)
            {
                if (Math.abs(bullets[i].x - x) < width / 2 && Math.abs(bullets[i].y - y) < height / 2)
                    health -= 50;
            }
            if (health <= 0)
                return true;
            return false;
        }

    }

}

Solution

  • You are using return false in a function with defined return value as void. You should change signature of the function CheckObj to:

    public function CheckObj(obj:Player, bullets:Array):Boolean