Imagine I create a MyBlock called function1 from a line of blocks. Can I call that block from within itself?


This is the program for the block recursiveTest.

Will this block function properly?


No, EV3 MyBlocks cannot be recursive. If a MyBlock contains a copy of itself, then the following error will be produced upon compiling:

The error produced when trying to put a MyBlock inside a MyBlock

For some reason, LEGO's programming software has become progressively less immediate about notifying you that this cannot be done. In EV3-G, it waits until compile to let you know that you can't do this. In NXT-G (the software for programming the NXT), trying to put a MyBlock in itself produces an error upon placing it. And in the Robotics Invention System 2.0 (the software for programming the RCX), it simply won't let go of the MyBlock you're dragging if you try and place it into itself.

If you want a programming language for the EV3 that supports recursion, I'd like to offer LeJOS EV3 (Java-based, free) and ROBOTC (C-based, costs money) as alternatives. They're both EV3-compatible, and support recursion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.