0

I'm trying to trigger a new state in a statechart with one message or another. Think about "waking up" a sleeping laptop with a message like "mouse click" or "keyboard stroke". Either action would wake it up, so how can you set that up?

I've tried declaring a boolean variable, setting the transition to "condition met" and creating a boolean-type expression, but got some StackOverFlow errors.

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
Brian Babo
  • 39
  • 4
  • Can you please [edit] your question to include your code? Also include the errors you got. For more info, see [How to Ask](https://stackoverflow.com/help/how-to-ask). This will make it much easier for volunteers to help you. – SecretAgentMan Dec 03 '19 at 21:59

1 Answers1

1

Do not use condition-based transitions, they only trigger when something else in your model also changes.

Much better to use a message-based transition and apply a logical OR statement like this i n the message-received box:

msg.equals("mouse clicked") || msg.equals("keyboard touched")

Notice the || signs acting as OR. More on that in the AnyLogic help section on Java

Benjamin
  • 10,603
  • 3
  • 16
  • 28
  • Thank you for the suggestion I will certainly use that. What if you require a certain amount of time to pass AND need a particular message? Almost like a hybrid of both a timeout as well as msg received? – Brian Babo Dec 04 '19 at 19:04
  • 1
    you code that :-) You'd need a timeout event in your agent and check if the event has timed out AND (&&) the other condition. Read up on events to learn how to set them up correct. PS: If this answered your question, please mark it as "helpful" (up-arrow next to the answer) so other users can find it faster in the future ;-) – Benjamin Dec 04 '19 at 19:57