Creating a Conditional Block with mBlock Extension Builder


#1

Hi Best_codes,

I have been trying to create a specialised IF Block Extension.
My plan is to use it with extra code especially for the LCD Block Extension I am creating.
It took me forever to workout I need a reference to the Boolean in my newly created IF Block. IE: lcd_iftest

Code:
if (/{lcd_iftest}/)
{

    lcd.print("Pressed!");
}

This allowed me to drop a Logic Operator where its needed, and it works. I am using a simple (number) = (number) Boolean to test, but previously I have created a Drop Box Boolean to test multiple options with the same Boolean.
So the IF part works, but I cant get the THEN part to function.
If I drop a LCD Print Command Block or any other Command Block, it does not populate the { } brackets like a normal IF Control Block. I tried references nothing has worked to date.

So is there any documentation that tells you how to create these Blocks that are available in the Extension Builder.
Because there are many other Functions there that I would like to investigate and possibly use.
What documentation I can find is very sparse and not detailed.

Thanks for your Help!

L84Brekky


#2

@L84brekky Assuming you want a behavior like this:

image

Then your code would be like:

if (/*{lcd_iftest}*/) {
  /*{$BRANCH1}*/
}

Using BRANCH1 to denote everything inside the block.

For reference, here is the code for the Repeat Until <condition> Block:

while(!(/*{{this.CONDITION ? this.CONDITION : 0}}*/)) 
{
  _loop();
  /*{$BRANCH1}*/
}

I believe that the Branches are as follows:
image
But I could be wrong so do your own testing with the Branch2 part.

Hope that answers your question!


#3

Thank you Best_codes the /{$BRANCH1}/ worked beautifully.

I tried adding a /{$BRANCH2}/ to a fresh IF Block but it didn’t do anything.
I suspect we need a IF ELSE Control Block to test it, but we only have the IF control Block available in the Extension Builder.

Thanks again.
L84brekky.


#4

@L84brekky No problem! I’m glad I could be of help.