Page 1 of 1
Blocky script, IF else if question
Posted: Friday 22 January 2016 21:42
by pcardon
Hello in the above sample I can't understand why the if block is executing, and just after the else if executes too ?

- blocky.jpg (77.5 KiB) Viewed 11363 times
and here is the log that shows the problem :
2016-01-22 21:39:00.428 SUN handler : SUNSET
<====================================
end ngRepeat: item in filtered = (logitems | filter:filterExpr) track by $index
2016-01-22 21:39:00.429 EventSystem: Event triggered: SUN handler_1
end ngRepeat: item in filtered = (logitems | filter:filterExpr) track by $index
2016-01-22 21:39:00.430 SUN handler : SUNRISE
<====================================
end ngRepeat: item in filtered = (log items | filter:filterExpr) track by $index
I'm sorry, i'm a starter with Domoticz and I'm sure I'm missing something
Regards
Pascal
Re: Blocky script, IF else if question
Posted: Saturday 23 January 2016 0:23
by tozzke
that's because when it's later than sunset, it's also still later than sunrise
You should do the following:
If [Time > Sunset]
or* [Time < Sunrise]
Do [Set var Jour_Nuit = "Nuit"]
Else if [Time > Sunrise]
and [Time < Sunset]
Do [Set var Jour_Nuit = "Jour"]
* Domoticz sees every time related event from and to midnight. So if you're crossing midnight with an event, you'll have to use 'or'
Re: Blocky script, IF else if question
Posted: Monday 25 January 2016 12:42
by pcardon
Hello,
Thank you for your answer,
I understand your answer, however, as far as I understand the "ELSE IF", this block should not execute if the "IF' block just executed ?
IF this is SUNSET ... set variable to "NIGHT" (NUIT in french) and quit ...
I'm missing something here ...
Please can you help me
Re: Blocky script, IF else if question
Posted: Monday 25 January 2016 17:42
by tozzke
it triggers just fine, no need to worry

Even better is this to prevent retriggering:
If [[Time > Sunset]
or* [Time < Sunrise]] and [var Jour_Nuit = "Jour"]
Do [Set var Jour_Nuit = "Nuit"]
Else if [[Time > Sunrise]
and [Time < Sunset]] and [var Jour_Nuit = "Nuit"]
Do [Set var Jour_Nuit = "Jour"]
Re: Blocky script, IF else if question
Posted: Monday 25 January 2016 18:38
by pcardon
Sorry to insist …
I understand that adding just supplementary tests will prevent retriggering, thats OK ...
But, I think the "ELSE IF" block should not execute if the "IF" block has executed ? Am I wrong ? Who can explain me that point ?
If I'm wrong, what is the "ELSE IF" utility ? this is something I don't understand here ...
Thanks for your help
Pascal
Re: Blocky script, IF else if question
Posted: Monday 25 January 2016 21:55
by tozzke
You are wrong

.
see
here for instance
the If-statement as well as the Else if-statement will trigger when conditions are met
Re: Blocky script, IF else if question
Posted: Monday 25 January 2016 22:25
by alfred_j_kwak
Did you read what it says?
An if statement follows this sort of structure:
if (condition) {
// executed only if "condition" is true
} else if (other condition) {
// executed only if "condition" was false and "other condition" is true
} else {
// executed only if both "condition" and "other condition" were false
}
As it says: executed only if "condition" was false and "other condition" is true
Re: Blocky script, IF else if question
Posted: Wednesday 27 January 2016 14:53
by pcardon
Yes I read what it says :
In my case, if (condition){
} is just true, it's 2016-01-22 21:39:00.428, so "IF" block is executed SUNSET, thats OK ...
BUT after I read :
else if (other condition) {
// executed only if "condition" was false and "other condition" is true
}
I read executed only if "condition" was false ... I think I understand ... So, if "condition" was true as seen above ... SO I UNDERSTAND the "else if" block should not execute ...
where am I wrong ?
later in the provided sample I read this :
/* If-ElseIf-Else Example */
if(condition_is_true){
do_this
}else if(different_condition_is_true){
do_this_only_if_first_condition_was_false_and_different_condition_was_true
}
I'm still blocking on your "explanations" … please
Re: Blocky script, IF else if question
Posted: Wednesday 27 January 2016 18:21
by alfred_j_kwak
Sorry pcardon. I wasn't clear. I mean that you are right with your problem. And tozzke made mistake.
Re: Blocky script, IF else if question
Posted: Friday 29 January 2016 12:54
by pcardon
Hello @alfred_j_kwak,
Thanks for your answer … does that mean there is a bug in the Blocky script engine ?
Is it possible to have a so big bug ?
Can somebody test on his Domoticz and see if he has the same problem …
I'm running Domoticz on a Synology, perhaps it's a specific problem to this distribution ...
Regards
Re: Blocky script, IF else if question
Posted: Friday 29 January 2016 17:13
by bizziebis
It has always been this way. It would be better if the name ELSE was not there. Because it only functions as IF, then.. IF, then etc.
This was the reason I switched to LUA scripting. When you want to solve it in Blockly you have to make large scripts which are sometimes hard to debug. To have one ELSE statement, you now have to copy your whole Blockly and add one different parameter so it will only trigger then.
Re: Blocky script, IF else if question
Posted: Monday 01 February 2016 17:28
by pcardon
bizziebis wrote:It has always been this way. It would be better if the name ELSE was not there. Because it only functions as IF, then.. IF, then etc.
This was the reason I switched to LUA scripting. When you want to solve it in Blockly you have to make large scripts which are sometimes hard to debug. To have one ELSE statement, you now have to copy your whole Blockly and add one different parameter so it will only trigger then.
Thanks you for this explanation …
So you know why I didn't understand … and that is different of all other "else if" implementations I ever seen
Re: Blocky script, IF else if question
Posted: Wednesday 18 January 2017 19:50
by nickb512
How has this issue not been fixed yet? Nearly a year later and one of the fundamental pieces of a programming language still doesn't work as expected. Is Domoticz still actively supported? Was considering moving from SmartThings until i discovered this.
Nick
Re: Blocky script, IF else if question
Posted: Saturday 25 March 2017 19:47
by Spitfire
Yes, it' s strange that an obvious bug like this isn't taken care off. Add to that...it would be nice if "Else" was implemented.
Re: Blocky script, IF else if question
Posted: Sunday 26 March 2017 19:14
by blauwebuis
Ah, this explains some weird behaviour..
Is there a fix on the horizon?
Re: Blocky script, IF else if question
Posted: Tuesday 12 September 2017 4:29
by motejowi
YES this is a big misunderstandig of programming fundamental rule!
I also discovered another bug, like in this code:
Code: Select all
If button = On
Do
If light = Off and a = 0
Do
Set a = 1
Set light = On
Else if light = On and a = 0
Do
Set light = Off
Set a = 0
In this example not only Else executes but also (if light = On AND a = 0) executes despite the 'a' was set to 1 in previous statement!
What's going on?
Domoticz, is this really kind of joke? This is not funny.
Re: Blocky script, IF else if question
Posted: Tuesday 12 September 2017 16:02
by motejowi
I committed an issue on Domoticz Github, if there's anyone interested / annoyed with it, can vote.
regards!
https://github.com/domoticz/domoticz/issues/1804
Re: Blocky script, IF else if question
Posted: Tuesday 12 September 2017 17:46
by pvm
I do not see a vote button
Re: Blocky script, IF else if question
Posted: Tuesday 12 September 2017 22:43
by motejowi
After signing in you can see a gray smiley with "Add your reaction" tooltip (top right corner of message frame).