Can't access lists in mBot program


#1

Hi All,

I’m writing a program that uses lists to hold data but the mBlock IDE keeps rejecting anything to do with accessing elements in a list or performing any list operation. I’m not liking the notion that I can’t store list data because the capstone program for a course I’m writing requires that capability.

Sample Program:

I get the following error dialog:

Since I’m teaching the class with mBlock, it will be very disappointing to have to say “and now we have to drop the visual programming environment because we need to do something that it can’t do…”

Any thoughts are appreciated.

Regards,

Chuck


#2

Hi Chuck,

Lists do work in mBlock, just not with mBot. I’m attaching some code that demos this, Concurrent.sb2 (74.9 KB). I’m not sure why it works one way and not the other.

Mike


#3

Hi Mike,

I’ve noticed that if I’m running tethered or via 2.4GHz wifi lists work fine with the click to start hat block. I suspect since mBlock is doing code generation under the covers that the infrastructure to handle lists is simply not there because of the way Scratch handles lists. I’ve dropped a note to support to get confirmation and I’m looking at the code on Github (not sure how current it is) to see what can be done. The biggest challenge would be to distinguish between strings and numbers because Scratch is not a strongly typed language.

Looking at your code, you’re doing similar things but when I try to switch to Arduino mode I get the error dialog complaining about unsupported list methods. Hopefully there will be a workaround at some point.


#4

I’ve already run into the scratch to C++ type issue in spades when working with IR messaging tests.
I’d also like to get the lists working in mBot.


#5

The Arduino code is closer to C in my mind (although you can certainly compile C with a C++ compiler) because I don’t see it doing any inheritance. The fix is relatively simple in my mind. if you always store lists as strings, then you convert to a float or an integer when needed for a calculation (atof/atoi/atol)) then convert results back to a string (sprint) to store it back in the list. It’s not the most efficient way to do things, but Scratch is really a constrained environment for this sort of thing anyway.

Snap! might have been a better choice to build off of. Snap! provides first class objects for lists, arrays, etc. and more importantly is written in Javascript rather than Adobe’s proprietary ActionScript. The latter is important because it would far easier to get people involved with it, especially if somehow it could be ported to run on the V8 Javascript engine. Connecting to Arduino bits would likely be much easier, but that’s just an opinion. :wink:

Update: Just saw that Snap is already connected to Arduino (https://github.com/edutec/Snap4Arduino). Snap4Arduino is Node.js-based and even runs on the Raspberry Pi!


#6

Then, I see that you can not handle lists in mblock for use in mbot. But, is there any extension or similar with functions for list management ?. Thanks


#7

If you run the program from within mBlock/Scratch, you can have lists. However, there are no plans that I’m aware of to implement this for the code generator used for standalone programs. The biggest issue that is likely holding it up is the amount of SRAM (variable memory) that is available after the Makeblock libraries are loaded is about 1K (1024 bytes) and it is reasonable to assume that it is intentionally not implemented to avoid crashing the Arduino. Inconvenient, but understandable.


#8