Sniff is a "Scratch-like" programming language that's designed to help Scratchers move gently from Scratch to more conventional languages. They can start writing programs, without having to learn a new language because Sniff is based on Scratch. They learn a little more about variables, compiling, syntax errors (!), and they can have fun controlling real hardware while they're doing it.

Monday, 24 March 2014

Release 5 = Minecraft

The Beta 5 release is now available on the Downloads page, and it contains lots of fixes, and improvements. However the one you're really interested in is Minecraft support!!!

While we love our gadgets, the main concept of Sniff is that its a programming language that lets experienced Scratch users move on to a "written" language that they will be familiar with. The need for this is made clear looking at the Python and Java examples that are provided with the Raspberry Pi version of Minecraft.

Minecraft has been released as a free download for Pi, with an option for external programs to tap into it, so that kids can learn to program by writing scripts to build things inside the 3D world. It's a great idea which is let down by the fact that one look at that examples provided will send any kid running and screaming. They're not particularly complex examples but even for an experienced (non-Python) programmer the syntax,  and code overhead makes them look difficult and hard to follow.

This exactly what Sniff is designed to avoid - Kids already know Scratch, which means that the Sniff syntax is familiar, so they can jump straight into problem solving, and making things! Introducing the Sniff Minecraft Device!

make minecraft device
make message string
make mcX number
make mcY number
make mcZ number
make blockType number
make blockData number

You make minecraft device and its variables like any other Sniff device. This sets up the connection to Pi Minecraft running on the current machine (if you want to use a different machine you can edit lib/Xminecraft.c - not recommended for public editing, but its pretty easy).

Now we can start doing things:

when start
.set message to "Sniff woz here"
.tell minecraft to "show"

broadcasts the message!

.set mcX to 5
.set mxZ to 5
.tell minecraft to "getHeight"
.tell minecraft to "setPos"

Moves the player to square (5,6). However before doing so, it checks the height of the land at that square, which sets mcY to the right value (Y is up) so that the player is standing on the ground rather than flying (or burried!). You can also check the players position with "getPos"

Now lets build a tower:

when start
.set mcX to 0
.set mcY to 0
.set mcZ to 0
.
.repeat 100
..tell minecraft to "getBlock"
..if blockType = 0
...set blockType to 1
...set blockData to 0
..else
...set blockType to 0
...set blockData to 0
..
..tell minecraft to "setBlock"
..change mcY by 1
..wait 0.2 secs
.
.set message to "like my tower?"
.tell minecraft to "show"

We set x/y/z to 0 (the spawn point). We check the block at that position, which gives us the blockType (ID). In addition blockData tells is more about the block (http://minecraft.gamepedia.com/Data_values). If the block is currently air (type 0), then we set it to 1 (stone), which builds a tower. If there's already a block there (because we've run the code before) we delete it by setting it to air.

There are other aspects to the Minecraft API, but they either provide duplicate ways of doing things we can already to with these functions, or they're not completely implemented/documented in the current release of minecraft for Pi. If I've missed anything that we should add, then either add it yourself (the files are there for you to change, and we'd love to receive your improvements), or email/DM/leave a comment letting us know.

So what are you waiting for? Go program Minecraft using Scratch like syntax!

No comments:

Post a Comment