Page 2 of 2
Re: Make blockly Else if to an actual else if
Posted: Saturday 24 February 2018 1:22
by ash77
Yeah, I spoke too soon. When m_events is filled from the database for Blockly events, it just remembers a set of condition/action pairs and doesn't remember which Blockly each pair came from.
For example, if I create this Blockly (call it A):
1. condition: temp < 25
action: .....
2. condition: temp > 26
action: .....
then I create a completely different Blockly (call it B):
1. condition: hum > 40
action: .....
2. condition: hum > 20
action: .....
When m_events is loaded, it contains:
1. condition: temp < 25
action: .....
2. condition: temp > 26
action: .....
3. condition: hum > 40
action: .....
4. condition: hum > 20
action: .....
with no way to determine that 1 and 2 came from Blockly A and 3 and 4 came from Blockly B. With the change I suggested, if #1 evaluates to true, it will never evaluate 3 which is incorrect.
It will be necessary to change the code in CEventSystem::LoadEvents() to retain EMID for each row from EventRules.
When a true condition is found (after parseBlocklyActions()), skip all remaining items in m_events with the same EMID as the one that was true.
All that being said, I agree with leonmoonen that this change is going to break some existing Blockly scripts. You can count on it.
Re: Make blockly Else if to an actual else if
Posted: Saturday 24 February 2018 9:22
by gizmocuz
@ash77, not sure i understand, but m_events (or the database is easier to check) is correct looking at your actions
You configured 4 actions (no complicated else stuff), and 4 actions are created and will be checked.
No need to know it is from A or B
Unless you meand that 2. condition: temp>26 was a 'else', in this case i can say that never worked and was/is the problem.
It won't break, making the patch will actually solve issues
Re: Make blockly Else if to an actual else if
Posted: Sunday 25 February 2018 23:20
by Xztraz
i guess this fix excludes else (only else) ? or is it possible to integrate that too?
Re: Make blockly Else if to an actual else if
Posted: Thursday 26 July 2018 10:01
by i3laze
I'm trying to implement
If [cond.] Do Else Do..
When I leave '
Else if' condition as empty,
Else Do-block doesn't fire.
Where can I get a '
True' block?
How about changing block's behavior for omitted condition to
'True' or adding simple
'Else' as a ⚙ block option?
Re: Make blockly Else if to an actual else if
Posted: Thursday 28 February 2019 19:33
by Lectere
I totally agree with Xztraz;
"As people have figured out Domoticz implementation of blocklys Else-If just works as a bunch of stacked if's. Not very logical."
"This should be rewritten to work as a real else-if and ordinary if-blocks should be stackable."
Again, I want to do something simple with Domoticz, and end up doing hours of research trying to get around something what I think is obvious. And no, this is not an opinion. The whole world threads it like a else, one of the conditions match, never more than one.
By using else if, it is possible to combine several conditions. Only the statements following the first condition that is found to be true will be executed. All other statements will be skipped.
source:
https://en.wikipedia.org/wiki/Condition ... ogramming) ;
I've actually tested it in c# and java, and both behave like a else should behave. Not like a bunch of stacked if's.
The whole discussion if it would break existing scripts is irrelevant, if you want Domoticz to be taken serious, this should be fixed regardless of people's wrongly written blocky's stop working. Of course a heads-up would be nice in the release notes.
I hope this get's priority over new features, for this is a actual issue.
Re: Make blockly Else if to an actual else if
Posted: Friday 01 March 2019 10:11
by supriyala
I agree with Xztraz.
Re: Make blockly Else if to an actual else if
Posted: Saturday 02 March 2019 16:08
by Xztraz
i think a rewrite of the blockly part would be very good for domoticz.
But it should be rewritten in such a way that it can generate code instead of just using the blocks as placeholders.
Imagine using blockly with all bells and whistles, if, else,math and whatnot, and if you need even more stuff later on you could easily just switch to lua(dzvents) and get your blockly code "exported" to raw code and continue from there. Could the blockly part be integrated with dzvents it would be awesome! and also a great learning experience for people to get more aquainted with real coding.
Re: Make blockly Else if to an actual else if
Posted: Saturday 02 March 2019 20:55
by dressie
Xztraz wrote:i think a rewrite of the blockly part would be very good for domoticz.
But it should be rewritten in such a way that it can generate code instead of just using the blocks as placeholders.
Imagine using blockly with all bells and whistles, if, else,math and whatnot, and if you need even more stuff later on you could easily just switch to lua(dzvents) and get your blockly code "exported" to raw code and continue from there. Could the blockly part be integrated with dzvents it would be awesome! and also a great learning experience for people to get more aquainted with real coding.
+1
It most certainly would bring Domoticz to the next level. I'll be happy and willing to test it!
Verstuurd vanaf mijn SM-G950F met Tapatalk
Re: Make blockly Else if to an actual else if
Posted: Sunday 20 September 2020 21:44
by WillJ
Hi Guys, sorry to revive an old post.
But I had a different approach to this topic.
It seems all this discussion is complaining that the else-if does not behave as expected and suggesting fixes.
Any changes to this would break all existing blockly implementations.
why not just do the following:
rename "else if" to "if"
That would make this much easier to understand for everyone and avoid the repeated questions on this topic.
Then, as a future improvement, "else" and "else if" could be added.
Just an idea!
Will