Rewriting the script

ScriptCraft: Hacking Minecraft for kids

Elliot Bentley

How do you get kids coding? A JavaScript wrapper to the Minecraft Java API is Walter Higgins’ clever solution.

How do you encourage kids to code?

Some might point to the example of Black Eyed Peas popstar promoting the joys of STEM on mainstream TV, or Google offering cash prizes at summer camps.

Another approach might be through video games, but even a basic game can take beginners weeks or months to create anything substantial. In an attempt to break down barriers to entry, IBM software engineer Walter Higgins created ScriptCraft, which incorporates JavaScript into popular indie game Minecraft to allow younger players to easily tap into the game’s flexible API.

The idea came to Higgins while attending CoderDojo, a volunteer-led scheme for teaching children programming and electronics at an early age, which he recently visited with his children.  “A lot of the kids learning to program JavaScript and HTML also love playing Minecraft,” said Higgins. “My hope is that when kids say ‘Wouldn’t it be cool if you could do X in minecraft’, they won’t go googling for a mod, they’ll write one themselves.”

Coded entirely in Java, Minecraft has also spawned a large and vibrant modding community, whose efforts have introduced the ability to travel back in time to the Jurassic age, pilotable biplanes and of course cats – as well as more boring tasks like administering external application servers.

“What I wanted to do with ScriptCraft was open up Minecraft modding to a wider audience and make modding more accessible for younger programmers,” said Higgins. As a challenge, he spent his three-week Christmas holidays creating a “kid-friendly” JavaScript API for children to use, with his eldest daughter serving as the project’s beta tester.

“It wasn’t as straightforward as I thought – Minecraft is proprietary so you can’t just go about exposing the internals via JavaScript,” he explains. “I decided to focus on creating an API for building structures instead – one that was fluent and used some of Logo’s commands – the goal being to teach kids the basics of building and moving about in 3 dimensional space and in the process giving them a taste of programming in JavaScript.”

The result, ScriptCraft, taps into the unofficial Bukkit API wrapper for Minecraft, allowing programmatic construction of Minecraft structures from the chat box (though Higgins has also demonstrated ScriptCraft’s ability to tap into events using explosive and teleportation arrows).

A simple demo: printing the current date and time.

But why not just use Java, rather than attempt to reinvent the wheel? “JavaScript is just easier,” says Higgins. “There’s no compile and build cycle. Accessing and setting properties is more succinct. Its duck-typing means programmers don’t have to explicitly cast to different types. Kids at CoderDojo sessions are already learning JavaScript so it’s a perfect fit for younger programmers.”

Higgins took advantage of the JVM’s built-in JavaScript engine, Rhino, which he describes as “Java’s (very) secret weapon”. “It’s been hiding in plain sight for more than a decade but it’s only with the resurgence of interest in JavaScript and its recent reappraisal as a bona-fide “proper” programming language (by the likes of Douglas Crockford and Steve Yegge) that Rhino’s been getting attention,” he says. “Rhino makes it possible to add scriptability to any Java based app.”

Rhino isn’t just useful for Minecraft modding, insists Higgins. “I do Enterprise Java programming (along with some JavaScript programming) in my day Job. Rhino makes for excellent ‘glue’ – for example adding custom build steps to Ant or Maven builds.” Despite this, he says he hasn’t been following the progress of Nashorn, the new JavaScript engine for the JVM coming in Java 8. “As long as it’s JSR223 compliant (which it seems to be) it should be good.”

Spurred on by “a lot of interest” in ScriptCraft at CoderDojo, Higgins has begun writing a Young Person’s Guide to Programming in Minecraft and plans to run workshops covering ScriptCraft’s Drone API. The source code for ScriptCraft is also available on Github, for those wanting to get their hands dirty.

Ultimately, says Higgins, the trick to getting kids interested in coding is to make it easier. “Java doesn’t have a REPL (Read Eval Print Loop) so it’s not conducive to exploratory programming. Combine exploratory programming with something kids are already keen on and that lowers a lot of the barriers to coding.”

Inline Feedbacks
View all comments