Processing/Java help

Soldato
Joined
6 Jun 2011
Posts
2,741
Hey guys,

I am currently creating a program using processing. However I am having a real problem with if statements. I have lots of different if statements which take up a lot of lines of code. I have tried putting them into a function using local variables, but the result of these if statements is to change a global variable and I cannot make it work. Here is the kind of thing I am talking about:


Any ideas? Any help appreciated.

Thanks :)
 
Last edited:
How many of these statements are you having? The event of mouseY = 250 isn't covered currently.

Try using an
if
else if

structure instead of just if statements, and see it fixed your problem



Though I'm still not entirely sure on what you are trying to accomplish.
 
The issue I am having is that each if statement is checking for the mouse position inside a button. The above code is an example but it is exactly what I have which works fine. However as I have so many buttons I have an awful lot of if statements and I was wondering if it is possible to use a function with one if statement that can be used for all.

Hope this makes sense.

Thanks :)
 
Can you not just do a function something like this? It does not work though because this is what I am having a problem with. I need the value of speed to be given to the example and example1 variable.



Thanks guys
 
Last edited:
Its difficult to tell what you're doing overall from the snippet you've posted, but a first step would be to use the built-in class for Rectangles: http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/Rectangle.html.

For a given rectangle object, you can then test whether a point (i.e. your mouse position) is inside using the contains(x,y) method.

A next step would be to handle a collection of rectangles using a list, array or map and iterate over them.
 
Hi there,

Thanks for the response. I have everything working, it's just I did not want a seperate if statement for each button. I was hoping I could have a kind of universal if statement in a function.

It's basically to cut the lines of code.

Thanks :)
 
Back
Top Bottom