Take the 2-minute tour ×
LEGO® Answers is a question and answer site for LEGO® and building block enthusiasts. It's 100% free, no registration required.

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

recursiceTestBlock

This is the program for the block "recursiveTest."

Will this block function properly?

share|improve this question

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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