Error while running VM code in VMEmulator

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Error while running VM code in VMEmulator

sarthak
When I run the code on VM Emulator (snake game code) I get error:
Illegal pixel coordinated.
I used Screen.drawPixel method to write the pixels and the coordinates seem fine to me.
How can I remove this error? game.zip 
Reply | Threaded
Open this post in threaded view
|

Re: Error while running VM code in VMEmulator

cadet1620
Administrator
Your program is asking drawPixel to draw a pixel that is off the screen.
OK the message box and hit the stop button on the VM Emulator.

The Call Stack shows snake.drawSnake called drawPixel.
class snake{
  field int length, dir;
  field Array x,y,coordinate, operation;
...
  method void drawSnake(){
    var int count;
>>> var Array x,y;         <<< delete this line
    let count = 0;
    do Screen.clearScreen();
    while (count < length){
      do Screen.setColor(true);
      do Screen.drawPixel(x[count],y[count]);
      let count = count + 1;
    }
    return;
  }
The local variable declaration of x and y overrides the field declaration
of x and y.  These local x and y are initialized with 0 so x[count] and
y[count] read values from RAM[0+count], and these values are too big to
be screen coordinates.