(Note: This is a work in progress.)
Here are things to check:
Here is a list of possible runtime error messages:
If you know which block is producing an error, the error message can help you figure out what is wrong. For example, if the message is "Needs a list" then one of the inputs of the block requires a list but is being passed a value of some other type (e.g. a number or string).
Unfortunately, MicroBlocks does not currently tell you which block caused an error. Thus, you may need to do some experiments to isolate the problem. For example, you can spilt a script to see if the error is happening in the first part of the script. If that part of the script runs without an error, you can add pieces until the error occurs. If the first part of the script gives the error, you can split that part further.
Error message are meant to be as self explanatory as possible. Some are clearly associated with a specific feature. For example, error messages that mention "I2C" are associated with the I2C communication blocks.
Unlike lists, byte arrays can only store numbers (not strings, booleans, or other objects) and those numbers must between 0 and 255. This error occurs if you attempt to store a non-number or a number outside of that range into a byte array,
MicroBlocks allocates memory for lists, strings, and byte arrays from a fixed-size memory pool. The amount of memory available varies by board. The memory is recycled when objects are no longer being used.
This error occurs when there not enough memory available to satisfy a request, For example, you will get this error if you try to create a list that is too large to fit in the available memory.
The free memory block in the Data category reports the number of words of memory that are available. Clicking the stop button will clear all global variables (set their values to zero) and free all allocated objects, maximimizing the amount of free space.
This error occurs when the function call stack becomes too deep. It is uncommon in small, simple projects but can occur as users create larger, more complex projects.
One possible cause of this error is using the list block with a large number of arguments:
This is an extreme example but even a list block with ten or twenty elements can contribute to this error when combined with other uses of the stack.
Sometimes it is better to build a large list by adding elements one at a time or by using the split block on a string representation of the list.
Another possible cause of the error is deep (or infinite) recursion. Accidental recursion can occur when a function contains a direct or indirect call to itself:
Intentional recursion with limited depth is possible in MicroBlocks. For example this works:
but not this:
Another possible cause for the Insufficient stack space error is a deeply nested calling sequence. That problem can usually be solved with some program restructuring. A useful tool that advanced users can use to understand their the structure of their function alls is the show call tree command on the define block for a function:
To avoid running out of stack space one should avoid deeply nested calls, calls that are deeply indented in the call tree report. In the example, the call to measureLoopOverhead is four levels deep. It uses 7 + 10 + 7 + 7 = 31 words of stack space. The maximum stack size is a bit over 50 words, so this program won't exceed stack space.