====== Tutorial 8 - Editing the function ====== ===== 3/4 ===== The function editing window has three tabs: * **Properties** - This tab lets you define the name of the function, and also lets you (optionally) describe the function parameters. * **Source** - Where the function code is written. * **Libraries** - Allows you to add dependent libraries and source files. - Make sure that the **Properties** tab is selected. - Enter the name “my_add” for the function. - Select the “Source” tab. The source page has a text box where you enter the source code for the function. A source template is automatically created for you, and is displayed in the text box. The areas in grey are not editable. The function method takes a [[http://en.wikipedia.org/wiki/Variadic_function#Variadic_functions_in_C.23.2C_VB.net.2C_and_Java|varargs]] parameter named “params”. When the function is called from Ecolego, all the function arguments are stored in this variable. For instance, consider an equation in Ecolego specifying “Comp1*my_function(A,B)”, where A and B are objects in your model. The values of A and B, at the time the function is called, will now be packaged into an [[http://simple.wikipedia.org/wiki/Array|array]], so that params[0] = A\\ params[1] = B The function ends with a “return Double.NaN” statement. You should here replace Double.NaN with the return value of your function. - Replace the text inside the white part of the text box with the following rows: double a=params[0]; double b=params[1]; return a+b; - Click on the **Test** button to make sure that the source code is valid. - Click ok to finalize editing of the function. **Next** * [[Tutorial_8-Using_the_function|Using the function (4/4)]] **Previous** * [[Tutorial_8-Creating_the_function|Creating the function (2/4)]] **References** * [[Tutorials|Back to Tutorials]] * [[start|Home]]