Scripting blocks

As a developer when you put a programming language inside your program its a good sign you’ve gone off the deep end. That is what I have done. I’m now going to try to justify why I’ve done this in an attempt to lie to myself that it was a good idea.

Scripting blocks are a response to wiring getting too complicated and ugly and look like this:

script block

The idea is that they can accept a small text program and replace a huge load of wiring with just a little bit of text. So they can convert something like this (which is an automated turret that tracks and fires at the player):


Into something like this:


This turret is actually something I intend to exist within spawned structures so I wanted the scripting block for my own use but I’m putting it as a general block for advanced players to use (see, justification).

Here’s a video of how its used:

The scripting block is available in the most recent version of One Million Worlds (version 0.4.3 onward)

So, that’s that done. Now its time for the documentation! Yay!


Once you’ve placed a script block look at it and press e to open up the script.

Inputs and outputs

The inputs and outputs are all referred to by the letters N,S,E,W,U,D for north, south, east, west, up and down. The N,S,E,W are shown on the chip itself, the up and down you’ll just have to figure out for yourself.

You can set a direction equal to a value and that value will be output to that directions. e.g.

N = 5


W = 'Hi there'

You can output to multiple directions in a single program

N = 5
W = 'Hi there'

You refer to the inputs in the same way, so say you have a number inputted in the West port and wanted North to be twice the West value you could use the following script

N = 2 * W //note that * means multiply

// indicates a comment, the rest of the line is ignored, so you can add notes to your script

Implicit outputs

If you only have one output equal to a simple equation (or want all your outputs to be the same) you can omit specifying what output you want the value to go to, so you can simplify the previous program to this:

2 * W //all outputs will receive a value twice the size of WEST

Asking questions

You can use the “if” keyword (and a whole bunch of brackets!) to do different things based on a question. So lets say you have an input W that is the distance away a player is (reported by a scanner block) and if the player is closer than 5 meters away you want to show on a screen (connected to N) “Go away” and raise a door (a Rail block connected to S) but if they do go away reopen the door you could use this program:

if(W<5){        // W is the distance away the player is
  N = 'Go away!'
  S = 4         //S is connected to a rail set to position mode, 4 is fully closed
  S = 1         //position 1 is fully open   


Sometimes you want to calculate something once and then use it several times, you can store it in a variable

someComplicatedCalculation= 2 * N + S
W = someComplicatedCalculation
E = 2 * someComplicatedCalculation


Sometimes a piece of data has several parts, like a position might have an x, y and z. These can be both read and creating within scripts. The main place you’ll see these is inputs coming from scanner blocks which report positions as an array of 3 numbers. For arrays that enter on inputs you can refer to them in 2 ways:

As x,y,z:

distanceAway = N.x      //N.x is the first value in the array, N.y is the second, N.z is the third
S = distanceAway

This way of referring to arrays only works with arrays entering on inputs, not ones you create yourself.

As a number:

distanceAway = N[0]      //N[0] is the first value in the array, N[1] is the second, N[2] is the third
S = distanceAway

Note that the first value is N[0], not N[1], arrays start at zero. 

You can create arrays using square brackets. for example this program would return an array of the numbers 1,2,3

N = [1,2,3]

You can of course use variables

distanceAway = N.x 
N = [distanceAway, 2*distanceAway, 3*distanceAway]

Inbuilt information

Some data is provided in variables for use in your script. At present these are:

  • firstRun – if this is the first time this script has run (i.e. you just edited it) this is true, otherwise its false
  • timeSlice – how much time this run of the script represents (aka how long there is between runs of the script)
  • scriptTime – the total time this script has run (its the sum of all the timeSlices since the script was changed)

Remembering things from the last time the script was run

Usually the script runs a fresh each time, forgetting all its variables, but it is possible to remember things from run to run, this is done using the persistent (or p) scope. Also because I really struggle to spell persistent you can also use the persistant scope and that will work fine. Anything in the persistent scope will still be available the next time the script runs.

So lets say we want to modify the “go away” script from the “asking questions” section so that if starts saying go away if you come within 5 meters but then it keeps saying it until you are 10 meters away:

    p.goAway = false //when the script first starts up default to not saying anything

if(W<5){     p.goAway = true } if(W>10){
    p.goAway = false
//note that if W is between 5 and 10 it is left at whatever value it had previously

    N = 'Go away!'

Inbuilt functions

I’ll be creating inbuilt functions as I need them (I’m selfish like that) for now these are available:

  • clamp – This will take a value and ensure it remains between two other values
N=clamp(W,5,10) //This will output the value of W, or 5 if W is below 5, or 10 if W is above 10
  • stabilise – This will provide functionality to stabilise a system, e.g. if you have a turret that’s looking at the player controlling a rotator block to make it look directly at the player…… its best explained by watching the above video. It is a PID controller that is used like:
stabilise(errorValue, proportionalTerm, integralTerm, derivitiveTerm)

The meaning of the terms are as follows:

errorValue –  how far the recorded value is from what you want it to be. E.g. if the player is 30 degrees to the left and you want to be looking at them the errorvalue is 30.
proportionalTerm – this is a tuning parameter, you need to play with it to see what works. You want to set it to a value such that your system swings quickly to the desired position (even if it overshoots)
intergralTerm – this is a tuning parameter, you need to play with it to see what works (you’ll probably want it to be zero. You can use it if you need to apply some force even if you are at the correct position (e.g. when you hold a weight up with your arm you still need to apply force even when you’re in the right position
derivitiveTerm –  this is a tuning parameter, you need to play with it to see what works. This controls overshoot, if the system keeps osculating about a set point increase the derivitiveTerm.


You don’t need loops, please skip this section.

Ok fine, loops are useful when you want to do something more than once.

A simple loop could be like this:

for(i = 0; i<5; i++){
   /*this area will be executed 5 times, 
   once with i as 0, then 1 etc until finally when i is 4*/

Lets say, in the “go away” example the closer they get the more you want to say go away, lets say one exclamation mark for every meter they get towards you. A loop can do that.

distanceAway = W
permittedDistance = 10
if(distanceAway < permittedDistance){
    message = "Go Away"
    exclamationMarksToShow = permittedDistance - distanceAway //closer they get the more exclamation marks

    for( i = 0; i < exclamationMarksToShow; i++){
        message = message + "!"
    N = message

Reading errors

If any problems occur with your script the errors are shown when you next open the script panel (note it doesn’t refresh until you open and close it). It will tell you the line number and letter number where it knew for sure that your script was wrong, its possible it went wrong before this but that’s its best guess at where it went wrong

Secretly its JavaScript

The script used within OneMillionWorlds is actually a variant of JavaScript. I’ve made some additions but broadly if your script is valid javascript it will work. I haven’t covered anywhere near the full features of the language so if you’ve got to this point and want more there are may resources for javascript available online.

Automated Rocket Factory

At the end of the last video I promised that I would could create a load of circuitry to fully automate the rocket factory, and while that is possible it would have been a lot of circuitry so instead of that I created a new block, the procedure block that allows the “do this, then this, then that” to be a lot easier to set up.


When you click into this block you get a simple UI that allows you to set up a series of outputs to run through


So with just that addition we can automate the rocket factory! Which I’ve put on top of a space ship, because why not.


Now due to certain, explosion related issues I realize I didn’t give you a close up view of the factory running, so here it is:


I’ve had a few videos of fairly military technology, but in the next video I plan on going in a more peaceful direction with a tunnel boring machine (that also collects and sorts any resources it finds along the way).

Rocket Factory!

I’ve been creating a couple of new blocks that help automate building:

A placer block that can place blocks, either as a new machine or attached to an existing machine


The placement block is part of the pipes system so you can use pipes to fill it up with things to place (or just open it and put things in manually)

And an attractor block that can pull other machines towards it (and lock them in position when they are close enough)


And with enough of them you can build a rocket factory:


An interesting question is if a sign post is a sensible way to input data into a machine, ………., its a fair point.

I mentioned a “more complicated circuit” running it all in the video but that feels a little complicated so I’m planning on adding a “procedure block” that you can set to [output the number 6 for 5 seconds then output the number 7 for 2 seconds] etc that should simplify that sort of thing.

A Block Battle

I’ve been looking at improving the sunspear AI this weekend (making it attack things that aren’t imaginary for example). Here’s a video of three of them attacking a player controlled vehicle.


3 verses one was never really going to go very well, still got 1 one of them!

You’ll probably have noticed the next item for improvement; the AI doesn’t 100% care about the ground, or trees, or other AIs and will happily crash into anything that isn’t its target.

You’ll see none of these ships are shielded, that’s deliberate, I’m making shield blocks very heavy so that you end up with a choice; heavy and shielded or light, maneuverable but vulnerable.

I’d like to end with a video of me actually winning, but well, this is the closest I ever got

2 Minute Hidden Cave

This is going to demo using the rails block, this allow one machine to run along a rail. In this case I’m using it to create a secret opening to a cave


So that’s great (he says modestly) but pushing things along rails can get boring fast. So can you power the rail so that it can move on its own?

I wouldn’t have asked the question if you couldn’t, so here’s the video


So a rail can be controlled not only by a button directly but remotely using antennas, which is, if I’m honest, much more useful.

You saw there was an addition/subtraction block. This is because a positive signal will move the rail one way, and a negative signal the other way


2 Minute Hovercraft

In the last post I showed a video of finished product; an aircraft, a hidden entrance, a turret and a car. which makes for a nice demo but doesn’t really show you how the game is actually played so I want to show some really short videos starting at nothing and building something that shows off a feature of the game. They may not be as pretty but they will be up and running quickly.

So to start; a 2 Minute Hovercraft


(Possibly that explosion at the end was a little over the top for a gentle crash into a tree, work in progress!)

So, that’s got engines to move, a command chair to bind keyboard input to the wire outputs, a skype notification noise (sorry about that, I did say these would be less pretty) and two weird looking blocks that didn’t seem to do anything:

antigrav and stabilisation

These blocks are “physics is hard, sort it out for me!” blocks. Or more specifically the antigrav block (gravity doesn’t affect any machine with one of these) and the stabilization block (keeps the machine more or less flat, the more of these you add the more it tries to keep it flat, but one is usually enough).

So what if you don’t have these blocks. I’m sure that would be fine.

No stabilization block:


No antigrav block:


Turns out a hovercraft without an antigravity block isn’t really a hovercraft. That said its utter failure showed off how blocks that get broken off machines become their own separate machines so I’m counting that as a success


I plan on using this blog to write about my progress writing my blockworld game. If the name “Blockworld” doesn’t mean much to you its because one game in particular dominates that genre, but it isn’t the only one. So this is a blockworld:


Great, so now we’re on the same page. Now a lot of you will have just said: “But that’s *REDACTED*!” and I’ll agree it does look pretty similar. So why do I want to remake a game that already exists? Well the answer is I don’t. Blockworlds you’ll have seen before tend to be fairly architectural; a building here, a bridge there, and if I’m honest that is already really fun, so many hours sunk, so many. But, when I was a child I didn’t make buildings and bridges out of Lego, I made spaceships and machines and things that moved (or at least that I imagined moving) and that’s what I wanted from my blockworld. Something like this:


That incidentally is something you could build in my game (I really need to decide on a title). You can see it has engines to move and maneuver and those green things on the end are energy projectors (weapons) linked up to sensors (the red blocks) all wired together to detect and shoot at hostile machines. But that particular ship is something that is also generated by the game and under Ai controll, it will wander around the world and if you shoot at it it will turn hostile and start shooting back and never forgive you (mental note; need to fix that last bit, slightly player hostile).

So; enough with the screenshots, I keep talking about “things that move” so here’s a video of all the things that move:

%d bloggers like this: