Data&Blocks


#1

I am very new to mbot and the scratch program format - I bought one for my kids to learn about robotics (and to learn something new myself). I have seen Data&blocks used in programs that I have seen posted in the forum. I noticed that if I make a variable ex. “Set” then 4 items go underneath it - set___to . Change by 1, etc. Is there a list of pre-programmed variables somewhere on the internet? Also, is there a tutorial available that explains how to create Data&Blocks?

Thanks,

Robb


#2

Try this wiki http://wiki.scratch.mit.edu/wiki/Data_Blocks


#3

Creating a variable, list or block is a matter of clicking on the Make a … button. You’ll see a dialog that has a place for a name, and a dropdown (signified by an arrow) next to the word Options. Under options, you can specify any incoming arguments and add labels to make the block name more readable. Variables can be named appropriately

For example, if you create a block named moveForward, you could add a label " at ", a number variable named Speed, another label " for ", and a number variable named Seconds.This would result in a block that reads:

moveForward at [Speed] for [Seconds]

The variables Speed and Seconds could be used internally in the block as local variables. They are not visible outside of the block.

Lists are just what they seem and act like a dynamic array. These data structures are not implemented for export to mBot programs and will only work from within mBlock.

Variables are just that, named storage although they can be manipulated as strings in some cases. The export of variables during mBot program generation, however, is quite literal, so strings have to be surrounded by double quotes or the Arduino compiler will throw an error.

One final thing. Avoid spaces in variable/list/block names. When you get to the point of using the Arduino IDE, the spaces are literally exported and will cause compilation errors. This is true for any programming language that isn’t graphically based (at least as far as I’m aware).

Hope this helps out.


#4

Hi,
I am just not being able to understand the creation of blocks and variables.

For e.g.

What does this mean ?

We define a block named (play)

Define (play(note))
Play tone on note (note)beat quarter

Why have they again defined note , when play had already been defined ?

Can someone explain in a simple and easy way or provide some reading material on this.

Thanks


#5

I have an ebook (link) that discusses this and other programming topics that you may find helpful. The proceeds go to a kids robotics fund.


#6

Thank you so much.


#7

One other thing I should mention is that mBlock is based on the Scratch 2 offline editor with robotic extensions that allow it to hook into the Arduino compilation environment. There are numerous Scratch tutorials online that will enhance your knowledge of Scratch.

Good luck!