Page 1 of 1

Blockly nested if?

Posted: Thursday 04 February 2016 0:00
by Dejvidno1
Is it possible to make nested if statements in Blockly? I'm using 2.4384 and can't get those green if-boxes togehter... :(

Re: Blockly nested if?

Posted: Thursday 04 February 2016 6:13
by Egregius
You need to use the AND/OR blocks, maybe together with a if/else if block.
The AND/OR blocks can be stacked.

Or, try scripting lua, php, bash... Way more flexible.

Re: Blockly nested if?

Posted: Thursday 04 February 2016 11:02
by Dejvidno1
Thanks, got it working in LUA. It wasn't so hard to at all. :)

Re: Blockly nested if?

Posted: Monday 19 December 2022 16:03
by Squonky
I've figured out how to do this in Blockly, for the 2nd time now. (I forgot, and figured it out again).

1. Select 'Control' from the LH Blockly constructs menu
2. Choose the 'If... Do...' option with the little blue '+' sign in the top LH corner
3. Click on that little blue plus sign to show the 'else if' options.
4. In the pop-up menu that appears, drag an 'else if' from the LHS of the pop-up menu into the mouth of the 'if' statement on the RHS.
5. Keep dragging more 'else if' blocks onto the 'if' statement in the pop-up menu - you should be able to create nested 'if... else if... else if... else if...' to your heart's content.
6. Click the blue '-' icon on the 'if... else if' statement in your code canvas to hide the pop-up menu. You're done!

To get rid of 'else if' clauses from your 'if... else if' statement:

1. On the canvas, open up that pop-up menu again from the little blue '+' icon
2. Drag unwanted 'else if' clauses from the RHS of the pop-up menu to the LHS. Removing them from the bottom up causes just one clause to disappear, whereas dragging the top 'else if' causes them ALL to disappear, and leave you with just an 'if' statement.

BTW, I have tried a couple of times in the past to do away with my Blockly scripts and convert to using a proper scripting language but it looked like an inscrutable minefield, so I gave up! :lol: