I have a transporter that carry parts to 3 different stations. The transporter has to check which station is empty and then it carries the part to the empty station. How I can program a method so that it is easy to find which station is empty at any given time instead of using if and else. is there any simple method for that? can anyone help ?
Solved! Go to Solution.
where do you want to avoid IF/ELSE-constructs? I guess you could have a cardfile of type object and an observer-method on each stations' EMPTY-attribute, which would append/remove this station from the cardfile when it is empty/non-empty. But I don't think that this would be better than having a simple method that loops through all stations and checks with IF/ELSE.
I think what you need is one separate method that returns either
The difference would be where you want to decide which station to choose if more than one is empty. But the question is also what you do (and how it's implemented) if currently all stations are full.
You could do something like
waituntil Sta1.empty or Sta2.empty or Sta3.empty prio 1; @.destination := m_getEmptyStation();
And the method m_getEmptyStation would look like this
:object is do -- return the first empty station (prefers Sta1 over Sta2 over Sta3!) if Sta1.empty then return Sta1; elseif Sta2.empty then return Sta2; elseif Sta3.empty then return Sta3; else debug; return void; end; end;
Does that work for you or what do you dislike about the IF/ELSE-construct here? (you could also loop over stations 1..x, then there is only 1 IF-block).