I create a Function for the setuptime. In the delay time in my service Block i write: f_getDuration(agent, v_Predecessor) v_Predecessor is my variable typ agent and i write this in on exit: v_Predecessor = agent;
But the if function are not working. The service Block does only take the last return 10. why does it not accept my function? Oberteil, Unterteil, Ring and Halteteil are my Agents. CurrentAgent and predecessor are Arguments Type Agent This is my function:
if (currentAgent == Oberteil && predecessor == Unterteil) {
return 45;
} else if (currentAgent == Oberteil && predecessor == Halteteil) {
return 40;
}else if (currentAgent == Oberteil && predecessor == Ring) {
return 45;
}else if (currentAgent == Unterteil && predecessor == Oberteil) {
return 45;
}else if (currentAgent == Unterteil && predecessor == Halteteil) {
return 40;
}else if (currentAgent == Unterteil && predecessor == Ring) {
return 45;
}else if (currentAgent == Halteteil && predecessor == Oberteil) {
return 40;
}else if (currentAgent == Halteteil && predecessor == Unterteil) {
return 40;
}else if (currentAgent == Halteteil && predecessor == Ring) {
return 45;
}else if (currentAgent == Ring && predecessor == Oberteil) {
return 45;
}else if (currentAgent == Ring && predecessor == Unterteil) {
return 45;
}else if (currentAgent == Ring && predecessor == Halteteil) {
return 45;
}
return 10;
I don't understand this very much.. but if Oberteil is an agent Type this means that the == is wrong
instead you should do
if (currentAgent instanceof Oberteil && predecessor instanceof Unterteil) {
etc...
Otherwise if this belongs to some kind of loop and Oberteil and Unterteil are actual agents that are defined, then you should do
if (currentAgent.equals(Oberteil) && predecessor.equals(Unterteil)) {
Try those
The answer from @felix is wrong, and you don't need the else before the return 10... since the return is only executed if all the previous conditions are false