We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I only started using Processing a few weeks ago and have been asked to set up a square on the screen (Simple).
While the mouse is outside the square it should give output of "Outside". Once I move mouse inside box it should output "Inside".
So far the below code is all I have come up with and it's not working for me. The box will come up but once I add the if and else statements I continue to get errors. I played around with curly brackets but I can't pinpoint the issue.
Can anybody help me please before I give up and throw the laptop into a river!! :((
TIA
float col = 0;
void setup() {
size(300, 300);
}
void draw()
{
background(255);
fill(0, 255, 0);
rect(125, 125, 50, 50,5);
}
{
if ((mouseX>125) && (mouseX<275) && (mouseY<275) && (mouseY>125));
println("Inside");
else
println("Outside");
}
Answers
@TfGuy44 :))
@supermick83 -- based on the mistakes you are making, in addition to solving your immediate problem I would strongly encourage you to re-read the introductory tutorial materials. Getting a firmer understanding of the basic concepts will save you a lot of time in the long run, as you won't make very simple mistakes over and over:
O.K.?
there is only
if
andelse
else if
just combines the effect by sayingif (blah)
is not the case, then tryif (blahahblah)
also, you are puttin the if statement outside of draw. in your case, you need it IN draw.
example:
hope you understand now.
He understood back in November 2017. Why re-answer a 4 month old thread?
that except he managed to get the brackets wrong... the if/else statement was outside draw... and i think he needs it to be IN draw as there are no other functions...
remove closing bracket after rect() and put a new one at the end of the file. should fix it.