Reputation: 29
I have issues with the following problem in AnyLogic:
I would like to create an event that is connected to a changing value of another variable. That variable can wheter be 1 or -1. At any moment it changes from -1 to 1, that event shall be triggered, but only once per occasion. Does anyone have a solution for this?
I already thought about implementing an boolean that checks that change, but I wouldn't know how.
Upvotes: 1
Views: 102
Reputation: 12785
You need to approach this the other way around.
You are trying to "monitor" the variable and wait for a change of it.
Instead, you should only allow 1 way to change that variable and add any additional model changes that come from it.
In OOP, you do it by:
myVariable
to access level private
public
function setMyVariable(int newValue)
next to itmyVariable = newValue;
AND any other code you want to be triggered whenever newValue==1
or newValue==-1
myVariable
is only ever changed via the function setMyVariable(...)
Upvotes: 2