Tiggers.no.tail wrote...
LOL, i just figured it out
you cant have the opening curly on the same lines as the name of the function
Looking at the lexicon, just now, it seems like it is mixing its words up. I have seen mix cases on the deffinitions of prototype and declaration in reguards to a function. my explanation is not going to use the word prototype. I woll call the prototype a 'forward delclaration'.
a Function declaration in NWN script takes the form of.
type functionName([type Argument1,] [...,] [type ArgumentN])
{
// code block ...
return value;
}
an example would be.
int AreaOfRectangle( int nHight, int nLength)
{
return nHight * nLenght;
}
in this example the first int is the data type that is returned by the function.
followed by the functiom Name of 'AreaOfRectangle'
followed by two argument withing the '()" of nHight and nLength. both having a data type of 'int'
the code block is a single return, that returns the product of the hight and length.
simple enough, There are times however when the scripter needs or wants to use a function before it is declaired. This is where the 'forward declaration come into play. A forward declaration allows the scripter to give the main body of a script just enough information to be able to compile the script without supplying all the information about what the function does. In short it is the same as the declaration but without the code block. the function does still have to be declared at some point in the scource code. IT just no longer has to be declaired befor it is used. The forward declaration take the form:
type functionName([type Argument1,] [...,] [type ArgumentN]);
Note the simicolon after the forward declaration. The simicolon basicly tells the compiler that the statment is copleate nothing else is comming. hence we know this is a forward declaration and a full declaration of the function will follow at some later point in the code. .
Now to answer your question. In order for the function to show up on the right side in the script editor, It has to have a forward declaration. The forward declaration and all comment lines preceeding it is what will show up in the help section at the bottom of the editor when the function is clicked.
Having a forward declaration immediately followed by the full declaration would be a bit pointless in most languages. In NWscript however you will notice it being done all the time, Just to have the forward declaration show up in the function list in the script editor. So in nwscript if I wanted my above function to show up and i had no reason to put the forward declaration elswhere in the script already. I would just define it with the forward declaration at the same time i declared it. along with any comments that i wanted to show up with it.
// Returns the area of the rectangle.
int AreaOfRectangle( int nHight, int nLength);
int AreaOfRectangle( int nHight, int nLength)
{
return nHight * nLenght;
}
Modifié par Lightfoot8, 03 septembre 2011 - 04:02 .