question

Lucas Z avatar image
0 Likes"
Lucas Z asked Mischa Spelt edited

Setting default values for user command parameters

Hello,

Is there a way to set default values for the parameters passed into a user command?

The C++ syntaxis doesn't seem to work. I would expect to be able to define it similarly. Am I just missing something trivial?

Thanks in advance!!

For example: I would like to define a function as below. But if I call this with one parameter only, I get the error that I am not passing enough parameters.

1696428428833.png



FlexSim 23.2.1
user commands
1696428428833.png (5.8 KiB)
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

·
Mischa Spelt avatar image
2 Likes"
Mischa Spelt answered Mischa Spelt edited

Hi Lucas,

In the parameters field, you can indicate that the parameter is optional as follows:

(double inputOne[, int inputTwo])

Then in the code, you can check the number of parameters using the parqty function and set the default if necessary:

int inputTwo = (parqty() >= 2) ? param(2) : 42;

where I have used 42 as the default value to distinguish it from the parameter index (2) in this example.

· 1
5 |100000

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

Lucas Z avatar image Lucas Z commented ·
Perfect, thank you Mischa!
0 Likes 0 ·

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.