We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › understanding PVector function
Page Index Toggle Pages: 1
understanding PVector function? (Read 577 times)
understanding PVector function?
Aug 28th, 2009, 6:19pm
 
hello, i was trying to understand the flocking code from processing examples and theres something new i never seen before, what does it means when you make this?
PVector align (ArrayList boids) {
}

why does he puts the name of a class instead of void? is this a different way to make a function? which are the differences with void?

thanks


M.
Re: understanding PVector function?
Reply #1 - Aug 28th, 2009, 6:55pm
 
It means the function returns a PVector. A lengthy discussion about how object oriented programming works could stem from this, but suffice to say, a function generally has three things appending its content: the return type, the name, and the parameters. In

PVector align (ArrayList boids) {
}

the return type is a PVector, the name is "align", and the paramater is an ArrayList called boids. If you look at the bottom of the method, you'll note that it returns "sum", which is a PVector. If the method returns nothing, then you append void.

When an object calls the align function, it will have to supply an ArrayList, and will expect a PVector in return.
Page Index Toggle Pages: 1