Why do my If/Else If statements not work correctly?


#1

1) Give a description of the problem
I want to receive a text when the dog feeder runs to let me know that the dog was fed. If, for some reason, the feeder runs again then I want a separate message to tell me the dog was fed twice.

2) What is the expected behavior?
I receive one message when the feeder runs that the dog was fed. If the feeder runs a second time, I would receive one message telling me that the dog was fed twice.

3) What is happening/not happening?
I receive a message that the dog has been fed AND a message that the dog was fed twice. These happen back-to-back each time the feeder runs.

**4) Post a Green Snapshot of the piston!


#2

If you post logs of a time when it sends messages twice, it’ll be easy to help you out. Without logs it’s just wild guesses and advice could end up making it worse.


#3

Okay, thanks. I’ll enable logging and post them up next time the piston runs!


#4

So, the dog is actually fed twice a day, correct? So, what do you want to know? I’d the dog feeder run a second time within what time frame?

Also, I would break up your first function a little differently. I would have

Power above…
IF time before noon
IF variable lists
Then action
Else (not else if) action
Else if time after noon
If variable list indicating it was first
Then action
Else (not else if) other action since it was the second.
Might make things a little easier to follow through execution. Also, you get one big false rather than a couple of them.


#5

Yeah, the dog is fed twice a day - once at breakfast and once at dinner.

In the event that the dog is fed breakfast or dinner more than once a day, which is why I cycle the breakfastfeed and dinnerfeed variables.

I’ll study your suggestion and see if I can get it implemented, thanks!!


#6

Alright, so I’m working on trying to restructure this to make it a little better, and I’m kind of stuck on your suggestion. Not sure how to do an else statement before an else if, as the else if comes before the else in webcore.


#7

My point is, I would remove the else If and just make it an else. But I would also “nest” your ifs inside of the previous. Maybe a better way to show it is .

If Power above…
      IF time between midnight & noon??
            IF variable lists
            Then action
            Else (not else if) action
     Else
             If variable list indicating it was first
             Then action
              Else (not else if) other action since it was the second.

#9

I finally had time to restructure this. Hopefully this is more along the lines of what your suggestion was: