Scriptcraft – A Little Friendly Vandalism

For this week’s sample script, building on the ideas developed the week before, I decided to pander to the crowd a little and show a script called tagger.js which allows you to ‘spray’ a design, in a block type of your choice onto the environment. It can be downloaded from here.

Description: Graffiti near Moganshan Road in Shanghai. Photographer: Jakub Hałun. Artist: Unknown. Source: Wikimedia Commons

Defining Our Design

The script contains an array of strings used to defined our design. In the array each string represents a row. Each character in those strings represents a block. Spaces are treated as blanks, anything else is a part of our design. Take a look at this specification which represents a peace sign:

var tag = ["   ***   ",
           " ** * ** ",
           " *  *  * ",
           "*   *   *",
           "*  ***  *",
           "* * * * *",
           " *  *  * ",
           " ** * ** ",
           "   ***   "];

It may be a little hard to make out at first, because characters are much narrower than lines are tall and the whole thing is stretched. Comparing to this drawing should help:

Peace Sign

Peace sign design for tagger.js

I’ve used asterisks in my strings just because it fills the space, but any non-space character will work just as well.

Spraying Onto What’s Already There

The fun thing about tagger.js is that it places the design on whatever is already in the world. It’s not restricted to flat surfaces!

The script looks at the area the player is facing and moves forwards, within a sensible limit, until it encounters a solid block (not air). If it finds one, it changes the block to the requested type. These diagrams show the operation.



If no block is found within the search depth, as has happened several times in the diagram above, that part of the design is left out.

In Action

Below is a screenshot of tagger in action: a big stone sphere with a love heart, made of red wool, and a partial smiley, made of gold blocks, sprayed onto it (partial because I was too far away when I called the script and some blocks were beyond the default depth).


Not Only … But Also

The script also has a few other little interesting features. In common with many of the standard Scriptcraft functions, this one shows how to check for parameters being left out and how to provide default values when that happens. It also shows how to retrieve a part of an existing string, used here to get a single character at a time. Take a look at the script yourself to see how this happens.

Week 5 – 2015 – Scratch Beginners

Hello everyone.

Good to see everyone there on Saturday. We made a game called Wipeout similar to on old game called Breakout.


We used a number of important coding concepts again this week, loops and decisions, Variables, broadcasting, etc.


Yesterday during class, we didn’t have time to add the Lives and the Scores but I am hoping everyone will try it themselves at home. We have done it many times now and I am sure you are well able to do it. Try it first on your own but I have put my game up on the scratch website so you can take a look at it if you get stuck. Here is a link Wipeout Game

No Coderdojo Athenry for the next two weeks but I hope to see you all back on the 7th of March.

Enjoy the break


PiDojo -week 1 : Getting started with the Raspberry Pi

Today we had our first PiDojo session. We had a short demo where we looked at what is possible with the Raspberry Pi.

We then had a search for projects where we saw loads of interesting ideas. We also set up one of our five new RPis.

We will continue working with the Raspberry Pi after the break so anybody who is interested can come along. All you need to bring is your laptop and an idea for a Raspberry Pi project.

Here are my slides from today Raspberry Pi presentation

Scriptcraft – Discovering the World


Thus far, we have used Scriptcraft to build cool structures in our Minecraft worlds, but the interaction has been a little one-sided. We’ve placed objects into the world, but we’ve never stopped to ask: “What’s already there?”.


That’s a powerful question to ask, because once we know what’s already in the world, our interaction with it becomes richer and opens up many new possibilities.

Objects in JavaScript

Objects in JavaScript have Properties and Methods. Properties are what they sound like; a value associated with object that we can get or set. Methods are actions, in the form of a function, that we can ask the object to perform.

If you thought of me as a Person object then you could imagine some of the Properties and Methods I might have. For Properties I might have things like NameAge, Height, Weight, etc. An example of a Method I might have could be SayHi() [notice the round brackets after the name marking this as a method]. That would make me say “Hi!”. A method might have arguments, so it could be SayHiTo(“Dave”) which would make me say “Hi Dave!”. A method could equally calculate a value. An example might be CalculateBMI() which would calculate my Body Mass Index (BMI) value based on my Height and Weight properties. On second thoughts… scratch that idea. SampleObject Exploring Existing Objects

How do we explore the objects in the ScriptCraft world? One way is to read the API documentation:

Another way is to look at the Scriptcraft code files themselves, especially drone.js.

Another handy, lazy, way to explore an object you already have a reference to in ScriptCraft is just to treat it like a string and pass it to self.sendMessage(). You’ll usually get a representation which shows some of the properties of the object and those properties’ values. It’s incomplete, but very quick and might show what you’re looking for.

Getting the Block Type

All of this was building to finding out, from Scriptcraft, what the block at a particular location is. Using a combination of the techniques listed above, I determined that I needed to call a method on the Bukkit World object called getBlockAt(). In Scriptcraft the server object has an array called worlds and the normal world is worlds[0]. For the curious; worlds[1] is the nether and worlds[2] is the end.

That’s everything we need to create a simple script to examine the block that we’re currently looking at. We can create a Drone, which is created at the block we are looking at by default, to get the location. Here is the main part of the code:

// Create a drone (will be placed at the block the player's looking at)
var d = new Drone();

// Gather information about the world, the drone's location
// and the block at the drone's location
var world = server.worlds[0];
var loc = d.getLocation();
var chunk = loc.chunk;
var block_info = world.getBlockAt(loc.x, loc.y, loc.z);

The remainder of the code is just printing this information to the console in a tidy way. We called it whats_that.js and it can be downloaded from here. The screenshot below shows it being run.


This will form the basis for some future projects.

Quick Final Note on Block Metadata

One final note and something that wasn’t discussed at our session last week: to fully define a block we need to know both its type and its metadata. Two wool blocks of different colours have the same type but different metadata values to distinguish them from one-and-other. Similarly steps use the metadata value to distinguish between the different possible orientations. You can use the whats_that() function to explore this.