ModderDojo Athenry Topic 6: JavaScript Operators and ScriptCraftJS Drone Functions

Operators:

Operators in any programming language are used when you want to calculate something new: they operate on values. variables, or expressions to produce a new value.

Since ScriptCraft is built on the JavaScript langauge, it uses standard JavaScript operators. As it happens, many other programming languages (including C, C++ and Java) use the same operators or very similar ones.

JavaScript Operators

Drone Functions:

As we have seen before, in ScriptCraft you use a drone to do your building for you. The drone has functions that are part of it.

Here are some of the main drone functions that are useful when building your mods:

ScriptCraft Drone Functions

You can find lots more about these and other functions in the ScriptCraft API Reference: https://github.com/walterhiggins/ScriptCraft/blob/master/docs/API-Reference.md

Example: Build a Pyramid

This example is based on a very nice program writing by Ruaidhri from Coderdojo Athenry last year, updated slightly because some ScriptCraft commands have changed in the meantime.


// Copyright Ruaidhri from ModderDojo Athenry,
// slightly updated by Michael and Alex.
// Builds a pyramid with entrance and lights inside.

exports.pyramid = function()
{
echo('making a pyramid');
var d = new Drone(self); // 'self' means start drone beside me
d.up(1);

d.chkpt('begin');

var size=31;

// Make the walls
while (size > 0)
{
d.box0(blocks.sandstone,size,1,size);
d.right(1);
d.fwd(1);
d.up(1);
size=size-2;
}

// Entrance
d.move('begin');
d.right(15);
d.box(blocks.air,1,2,3);

// Lights inside
d.move('begin');
d.right(4);
d.fwd(4);
d.up(3);
d.turn(2);
var t = 0;
while (t<4)
{
d.hangtorch();
d.left(11);
d.hangtorch();
d.left(11);
d.turn(3);
t = t + 1;
}
d.move('begin');
}

Minecraft Modding Taster Session – Week 1

Slide1

This season at CoderDojo Athenry, the advanced groups are all starting with taster sessions of the various topics we will cover.

In Week 1, the topic we are covering is Minecraft Modding using JavaScript.

Here are the notes:

  1. Getting Started with ScriptCraft and JavaScript
  2. How to Connect to Each Other’s Servers
  3. Creating our First ScriptCraft Mods

Coming up next week: in introduction to Raspberry Pi and Electronics