NickA
NickA

Reputation: 443

Conditional statement in SelectOutput checking for 2 conditions anylogic returning error

I am trying to set 2 conditions that have to be checked inside the Condition field of selectOutput. If the entirety of the first line is false, I want the entirety of the second to be checked. However, using the code below, I am returned the error that only shows for the first instance of == of the second statement:

Syntax error on token "==", invalid AssignmentOperator

agent.isMorning == true && doctorMorning.idle() == 0;

agent.isMorning == false && doctorAfternoon.idle() == 0;

Upvotes: 0

Views: 250

Answers (2)

slepax
slepax

Reputation: 83

Since Java supports lazy evaluations, this should do what you want:

(agent.isMorning && doctorMorning.idle() == 0) || (!agent.isMorning && doctorAfternoon.idle() == 0)

Upvotes: 0

Benjamin
Benjamin

Reputation: 12795

You can package conditions into nested conditions as below: enter image description here

Now the agent will continue on the "true" exit if the entire first line is true, else it will check the third line and follow whatever boolean that returns.

NOTE: You cannot use ; in these 1-line condition code boxes. If you want to write longer code, you must create a function that returns a boolean and call that instead. Especially for complex nested statements like yours, it is often much easier to create a specific function

Upvotes: 2

Related Questions