User Tools

Site Tools


tutorial_8-editing_the_function

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.
  1. Make sure that the Properties tab is selected.
  2. Enter the name “my_add” for the function.
  3. 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 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 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.

  1. 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;
  1. Click on the Test button to make sure that the source code is valid.
  2. Click ok to finalize editing of the function.

Next

Previous

References

tutorial_8-editing_the_function.txt · Last modified: 2023/03/31 14:31 by dmytroh