Setting default values for user command parameters

Setting default values for user command parameters

lucas_z
Not applicable
324 Views
2 Replies
Message 1 of 3

Setting default values for user command parameters

lucas_z
Not applicable

[ FlexSim 23.2.1 ]

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



0 Likes
Accepted solutions (1)
325 Views
2 Replies
Replies (2)
Message 2 of 3

mischa_spelt
Advisor
Advisor
Accepted solution

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.

Message 3 of 3

lucas_z
Not applicable
Perfect, thank you Mischa!
0 Likes