Custom Extension generated code in incorrect order


#1

Hi, Ia have created an Extension to be used with an arduino car. I can install the extension and it generates code properly but if I mix my blocks with arduino ones the code of the arduino block is always inserted before mine no matter where I put my block.
Example:
Add “Arduino Program” from Arduino extension
Add “Init Car” block from my extension
Add Serial.Print(“Car initilized”) from Arduino extension.

And the resulting Arduino code is

void setup(){
Serial.begin(115200);
Serial.println(“Car Init”);
pinMode(enableRight, OUTPUT); <-- Begin Init Car
pinMode(enableLeft, OUTPUT);
pinMode(rightMotor1, OUTPUT);
pinMode(rightMotor2, OUTPUT);
pinMode(leftMotor1, OUTPUT);
pinMode(leftMotor2, OUTPUT); <— End Init Car
}

If I add more blocks from different extensions mBlock seems to order my extension code lines together,not in the order I added the blocks

Miguel


#2

It is helpful to place a picture of blocks.
But your problem is that you incorrectly placed code in your extension, or you don’t use block “Forever”.
Code in section “Setup” not very important the order in which blocks are located.

Use block “Forever”, or replace code from “Setup” to “Work” in your extension.


#3

You are right, I misunderstood the block type use (work, setup) etc. I didn’t use the loop because I was trying to do some simple movements once.

Now I use the loop and the code is ordered but some more info on how to make extensions would be great.

Thanks for your help
Miguel


#4

The site has good instructions, but you probably already read it (http://www.mblock.cc/docs/create-extensions-for-mblock/). Further experience and common sense.

I described my experience of creating extensions and gave practical advice on one site, but there all in Russian, in English it is difficult to write large texts for me.

So write on this forum, there are many practitioners who will help.