Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

PongGame Errorcode: ArrayIndexOutOfBoundsException 1.

$
0
0
I got always after 1-2 minutes the same errorcode and just the client crashes. The Compiler marks always the line 94

I rly dont know why. Here is my code for the client and server: 

  1. //Server

  2. import processing.net.*;
  3. Server myServer;
  4. Client myClient; 
  5. String input;
  6. float data[];
  7. int val = 0;
  8. int rad = 20;        // Width of the shape
  9. float xpos, ypos;    // Starting position of shape    

  10. float xspeed = 5.6;  // Speed of the shape
  11. float yspeed = 4.4;  // Speed of the shape

  12. int xdirection = 1;  // Left or Right
  13. int ydirection = 1;  // Top to Bottom

  14. void setup() {
  15.   size(600, 400);
  16.    noStroke();
  17.   frameRate(30);
  18.   ellipseMode(RADIUS);
  19.   // Set the starting position of the shape
  20.   xpos = width/2;
  21.   ypos = height/2;
  22.   myServer = new Server(this, 9000); 
  23. }

  24. void draw() {
  25.  background(102);

  26.   // Update the position of the shape
  27.   xpos = xpos + ( xspeed * xdirection );
  28.   ypos = ypos + ( yspeed * ydirection );
  29.   
  30.   // Test to see if the shape exceeds the boundaries of the screen
  31.   // If it does, reverse its direction by multiplying by -1
  32.   if (xpos > width-rad || xpos < rad) {
  33.     xdirection *= -1;
  34.   }
  35.   if (ypos > height-rad || ypos < rad) {
  36.     ydirection *= -1;
  37.   }
  38.   // Draw the shape
  39.   ellipse(xpos, ypos, rad, rad);
  40.   myServer.write(xpos + " " + ypos + " " + rad + " " + rad + "\n");
  41.  
  42.   myClient = myServer.available();
  43.   if (myClient != null) {
  44.   input = myClient.readString();
  45.   data = float(split(input,' '));
  46.   print(input);
  47.   }
  48. }


  49. //Client
  50. import processing.net.*; 
  51. Client myClient; 
  52. int dataIn; 
  53.  String input;
  54. float data[];
  55. void setup() { 
  56.   size(600, 400); 
  57. noStroke();
  58.   frameRate(30);
  59.     ellipseMode(RADIUS);


  60.   myClient = new Client(this, "127.0.0.1", 9000); 
  61.  
  62. void draw() { 
  63.   background(102);
  64. if (mousePressed == true) {
  65.     // Draw our line
  66.     stroke(255);
  67.     line(pmouseX, pmouseY, mouseX, mouseY);
  68.     // Send mouse coords to other person
  69.     myClient.write(pmouseX + " " + pmouseY + " " + mouseX + " " + mouseY + "\n");
  70. }
  71.   if (myClient.available() > 0) { 
  72. input = myClient.readString();



  73.   input = input.substring(0, input.indexOf("\n")); // Only up to the newline


  74.     data = float(split(input,' ')); // Split values into an array
  75.    
  76.   
  77.     ellipse(data[0], data[1], data[2], data[3]);
  78.     print(input);
  79.     
  80.   } 


Viewing all articles
Browse latest Browse all 1768

Trending Articles