The Function always take the last return

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; 

>Solution :

Right now, the function will always return 10 because this is not part of the "if-else" block (it overwrites the return values). If you only want to return "10" if the other conditions do not hold, put an "else" before "return 10;"

Leave a Reply