Showing results for 
Search instead for 
Did you mean: 

Inspecting the empty station


Hello Everyone,

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 ?


Betreff: Inspecting the empty station

Gears Phenom Gears Phenom
Gears Phenom

Hi k_parashar,

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

  • one of the three stations (which?) that is empty 
  • OR an object-list with all empty stations.

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

  -- 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;
    return void;

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).


Alex Dilg, Consultant at SimPlan AG (
This post was good and/or helpful to you? Please provide some Kudos, thank you!

Betreff: Inspecting the empty station

Thanks Alex_D, the waituntil approach worked in my case. I also tried to do with if-else and found that easier then using cards, although has to repeat code for each staion.