question

Mark S3 avatar image
0 Likes"
Mark S3 asked Mark S3 commented

How do I call a custom function from within another custom function?

I defined the Fun1 function.If I want to use Fun1 in Fun2, how do I do it?

qq图片20211231133807.png

FlexSim 21.2.0
dll maker
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Phil BoBo avatar image
3 Likes"
Phil BoBo answered Mark S3 commented

Don't call FLEXSIMINTERFACE functions from another C++ function.

Add a different function with its own signature and call it from both of those functions.

double Fun1_cpp(double a, double b)
{
  return a+b;
}

visible double Fun1(FLEXSIMINTERFACE)
{
  double a = param(1);
  double b = param(2);
  
  return Fun1_cpp(a, b);
}

visible double Fun2(FLEXSIMINTERFACE)
{
  double a = param(1);
  double b = param(2);
  double c = Fun1_cpp(a, b);
  
  return c;
}

or

double Fun1(double a, double b)
{
  return a+b;
}

visible double Fun1_FS(FLEXSIMINTERFACE)
{
  double a = param(1);
  double b = param(2);
  
  return Fun1(a, b);
}

visible double Fun2_FS(FLEXSIMINTERFACE)
{
  double a = param(1);
  double b = param(2);
  double c = Fun1(a, b);
  
  return c;
}
· 8
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Mark S3 avatar image Mark S3 commented ·

Thanks for your reply. But my picture is just a simple example. In fact, Fun1 and Fun2 are custom user commands that use flexsim functions and syntax. I find it very convenient to call Fun2 in Flexsim, but I don't know how to do it in DLLMaker, that's what I'm confused about.

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦ Mark S3 commented ·

If you're saying that you want to call a FlexSim user command from the DLL maker then your example isn't showing what you wanted to do - hence Phil's reply. In that case you should be able to use nodefunction() on the user command flexScript node or node.evaluate() which should run the command and return the result.


0 Likes 0 ·
Mark S3 avatar image Mark S3 Jason Lightfoot ♦ commented ·

Both Fun1 and Fun2 functions are defined and implemented in DLLMaker. Then back in Flexsim, Fun1 and Fun2 are used as user commands .

The picture below shows a simple example. In fact. The Fun1 function can be more complicated. I want to call Fun1 from Fun2 .

qq图片20220106174500.png

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.