@LordMaddog ah, that is a good question.
You see, computers, although capable of doing amazing things, aren’t intuitive like you and I. So in programming we have to be very exact about what we do.
by using ()
we are telling the computer that the word that came before it was the name of a function.
findNearestEnemy
by itself should refer to a variable, in other words it stores something.
findNearestEnemy()
is a function so it does something.
if you are good in linguistics this is where I could say that findNearestEnemy
is a noun and findNearestEnemy()
is a verb.
does that make more sense?
Again as computers are not very smart, we need to give structure to everything we write. So when we declare a function
local AaD = function()
-- some code
end
We need to tell the computer that yes this is a function and no we are not sending anything to it, empty ( )
.
if this function was able to take an object and do something with it then we could declare it as follows:
local cleanAndScrub = function( theDishes )
-- theDishes is an array of things to wash
local firstDish = theDishes[0]
clean(firstDish)
scrub(firstDish)
end
Functions can manipulate things just like you or I can. We can wash the dishes and help out (and ought to) just like the function shown above. This is how functions were chosen to be created. Because it is useful to work on things.
So the parenthesis are our structure, like a persons hands, they hold objects inside that were sent to the function to work on. By the way these objects we are talking about are referred to as arguments in programming.
Does that help a bit?
If you didn't know, you can use the forum text editors "Formatted Text" button after highlighting your code blocks to make the pretty like mine are. Shown below:
-HW