I really need help here, esp with the return number bit in bold, I am trying to return a number depending on where the ball is in the pong grid (yes i went a long way around with the grid). The eventual idea is the number will be sent to Max and then logic to make certain chords go off etc. When i run the code it tells me "unexpected token float" but without it, it tells me that it needs a float. the underlined solutions were suggested to me, but I don't really understand what's going on. I'm a beginner, so if you do help, please assume i know NOTHING. i'm just trying to get it to work, i'm not worried if it's a bit unwieldy and too long.
import oscP5.*; //import libraries
import netP5.*;
//paddle variables
int paddlerightX, paddlerightY;
int paddleleftX, paddleleftY;
int widthpaddle = 10, heightpaddle = 50;
// ellipse (ball) variables
float ellipseX, ellipseY;//
float speedX = 1, speedY = 1;
float ellipseSize = 10;
float directionX = 1, directionY = 1;
//declaring global variable to start pong
boolean startPong=false;
//objects
OscP5 oscP5Connect;
NetAddress sendingLocation;//declaring the objects for later
OscMessage messageToSendToMax;
void setup() //background/game interface, runs and stays
{
size (400, 400);
// variable values needed here for the declared variables above
paddlerightX = width - 10;
//paddlerightY;
paddleleftX = 0;
// paddleleftY;
ellipseX = width/2;
ellipseY = 0;
oscP5Connect = new OscP5(this, 9000); // incoming from ipad
sendingLocation = new NetAddress ("127.0.0.1", 8000); // processing to max
}
void draw()
{
background(0);
if (startPong ==true)//boolean to start pong
{
ellipseBounce();
}
fill (0, 255, 0); //colours ball and rects
ellipse(ellipseX, ellipseY, ellipseSize, ellipseSize);//draws the ball
drawInterface();//function to draw interface called here
paddlePosition();
drawPaddles();
ellipseBounce();
tellMaxToStart();
tellSpeed();
startUltra();
// ballSpeed(); //this function has an argument, float s, and is called here and created below.
EvenOrNot();
//makes the ball move
}
void ellipseBounce ()
{
//y radius
ellipseY = ellipseY + (directionY*speedY); //flips the ball back if it goes outside the 400 x 400 frame
if (ellipseY > height || ellipseY < 0)
directionY = directionY * -1;
// x radius
ellipseX = ellipseX + (directionX*speedX);//flips the ball back if it goes outside the 400 x 400 frame
if (ellipseX > width || ellipseX < 0)
directionX = directionX * -1;
}
void oscEvent(OscMessage receivedMessage) //I adapted laura Maye's patch here.
{
if (receivedMessage.checkAddrPattern("/1/ballspeed"))
println("the current ballspeed is:" + receivedSpeed);
}
if (receivedMessage.checkAddrPattern("/1/pongtoggleout"))
{
float begin = receivedMessage.get(0).floatValue();
if (begin == 1.0)
startPong = true;
else
startPong = false;
println("StartPong is set to:" + startPong);
}
}
void ballSpeed(float s)
{
speedY = s*3 + 1;
speedX = s*3 + 1;
}
void drawInterface()//draws the screen,
{
strokeWeight(1); //makes the line more visible cos it has an outline
for (int i = 0; i<height; i+=10) // for loop to tell it to draw the rects continually and at a space of 10 until it goes the lenght of the defined screen
{
rect (200, i + 10, 5, 15); // line down screen centre this for loop tells it to keep drawing as long as it is less than the height
}
}
void drawPaddles() //draws the paddles
{
fill (247, 15, 42);
rect (paddleleftX, paddleleftY, widthpaddle, heightpaddle);
rect (paddlerightX, paddlerightY, widthpaddle, heightpaddle);
}
void paddlePosition()//makes them move and not disappear
{
//RIGHT PADDLE
paddlerightY = paddlerightY + 3;
if (paddlerightY > height - 50) //ensuring the paddle doesn't go off the bottom of the screen
//This bit figures out where the ball is, and returns a number depending on the location and then sends this number and message to max to do things over there.
float gridLayout (float px, float py)//function for the grid
{
float numberToReturn = 0
//first line of grid boxes 1-4
if (px < width/4 && py > height/4)// it's in the Q1 (Q = quadrant)
numberToReturn = 1;
return 1;
else if (px < width/2 && px < width/ 4 && py < height/4) //it's in Q2
numberToReturn = 2;
return 2;
else if (px > width/2 && px < width/4*3 && py < height/4) //it's in q3
numberToReturn = 3;
return 3;
else if (px > width && px > width/4*3 && py < height/4) //it's in Q4