Make blockly Else if to an actual else if

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

ash77
Posts: 8
Joined: Wednesday 10 June 2015 22:10
Target OS: Windows
Domoticz version:
Location: United States
Contact:

Re: Make blockly Else if to an actual else if

Post 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.
User avatar
gizmocuz
Posts: 2352
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Make blockly Else if to an actual else if

Post 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
Quality outlives Quantity!
Xztraz
Posts: 107
Joined: Tuesday 31 January 2017 21:54
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Make blockly Else if to an actual else if

Post by Xztraz »

i guess this fix excludes else (only else) ? or is it possible to integrate that too? :)
User avatar
i3laze
Posts: 7
Joined: Thursday 26 July 2018 9:48
Target OS: Windows
Domoticz version:
Contact:

Re: Make blockly Else if to an actual else if

Post by i3laze »

I'm trying to implement If [cond.] Do Else Do..

When I leave 'Else if' :arrow: condition as empty, Else Do-block doesn't fire.
Where can I get a 'True' block? :D

How about changing block's behavior for omitted condition to 'True' or adding simple 'Else' as a ⚙ block option?
User avatar
Lectere
Posts: 24
Joined: Saturday 04 April 2015 8:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Re: Make blockly Else if to an actual else if

Post 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.
Effictent and redundant two-factor authentication? http://www.smspassword.com
supriyala
Posts: 1
Joined: Friday 01 March 2019 10:07
Target OS: Linux
Domoticz version:
Contact:

Re: Make blockly Else if to an actual else if

Post by supriyala »

I agree with Xztraz.
Xztraz
Posts: 107
Joined: Tuesday 31 January 2017 21:54
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Make blockly Else if to an actual else if

Post 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.
dressie
Posts: 156
Joined: Monday 25 May 2015 22:44
Target OS: Raspberry Pi / ODroid
Domoticz version: V2020.2
Location: Netherlands
Contact:

Re: Make blockly Else if to an actual else if

Post 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

WillJ
Posts: 2
Joined: Sunday 20 September 2020 21:38
Target OS: -
Domoticz version:
Contact:

Re: Make blockly Else if to an actual else if

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests