Search code examples
arraysactionscript-3flash

Receiving an error in Actionscript 3. "Comparison between a value with a static type uint and a possibly unrelated type Array"


Forgive me for my lack of understanding, I am only a high school student. For a school project, I am tasked with creating a game through Actionscript 3. I have decided to make Brick Breaker, where the objective is to destroy the blocks on stage, etc. One of the features of the game is that blocks with varying types are spawned on screen. The red type can be destroyed in one hit, the blue can be destroyed in two hits and the purple type can be destroyed in three. These three blocks have been added to 'blockArray'.

Basically, when the ball hits one of the blocks, it will lose a health point. When the block has health = 0, then it will remove from stage and Array.

The spawning and collisions of the ball hitting the blocks work just as they should. The problem is pretty much everything else. Let me show you an example:

function checkHealth():void
      for (var i:uint=0; i<blockArray.length; i++)
           for (i = 0; i < blockArray; i++)
                health = 1;
           for (i = 1; i < blockArray; i++)
                health = 2;
           for (i = 2; i < blockArray; i++)
                health = 3;

I am getting an error from this code saying, "Comparison between a value with a static type uint and a possibly unrelated type Array"

Any help for this is much appreciated, Thank you.


Solution

  • This code contains some very wrong practices, and doesn't really make sense.

    Assuming the second for loop runs 50 times, why would you want to assign the same value to a variable 50 times? "health = 1" can be called only once. Calling it 1 million times wouldn't change the result.

    Also, modifying the index value inside the for loop itself is very bug friendly :) I wouldn't do that. Can you explain better what you want to achieve? By reading this code it is impossible to guess.