Creators – Being Random

Screen Shot 2017-10-17 at 00.56.49

This week we mainly looked at three things:

  • How data is organised on your computer
  • Creating functions
  • Using randomness to make things interesting

Data Organisation

Most of us had heard of a hard-disk before. This is a stack of metal disks inside your computer. Each metal disk has a special coating made of millions of tiny magnets (like you might find stuck to the fridge) that can be turned on and off.11644419853_9499fa0faa_b

We saw that able to turn something on and off, like a switch, was enough to count from zero to one, but the more switches we added, the higher we could count. Two switches can count from zero to three:

Switch 1          | Switch 2          | Total (Add)
[Off = 0, On = 1] | [Off = 0, On = 2] |
Off = 0           | Off = 0           | 0
On  = 1           | Off = 0           | 1
Off = 0           | On  = 2           | 2
On  = 1           | On  = 2           | 3

With enough of these tiny switches, we can store anything we need. Each of these tiny switches is also known as a ‘bit’ and a 1 terabyte hard disk has a billion of them!

We also saw that the files on your disk are arranged with folders (also known as directories). Folders can contain both files and more folders. This allow us to keep our hard disk organised; without them all our files would be in the same place which would be difficult once we had more than a few. The location of a file is called its “path”. Looking at the highlighted file on the desktop of my Mac we can see the full path would be:

Screen Shot 2017-10-16 at 22.19.59

/Users/kierancoughlan/Desktop/Ball and Bat Sounds.m4a


This means that, reading backwards, the file called ‘Bat and Ball Sounds.m4a’ is in a folder called ‘Desktop’ which is itself inside a folder called ‘kierancoughlan’ which is, at the highest level, inside a folder called ‘Users’.


A function is a collection of commands that do a job together. We’ve already encountered them, even if you hadn’t especially noticed:

  • Our P5 template already contains two functions called start() and draw()
  • All of the P5 commands we have used, such as createCanvas() and rect() are functions themselves

We could add all our code to start() and draw(), in fact, that’s what we’ve done before this week. That’s fine starting out, but it does mean, once there are a lot of commands in those functions, that our code is gets harder to read and understand. Breaking out a few commands into a new function and giving it a name that describes what it is doing, really helps.

Once we’ve written a function, it can be called as many times, and from as many places, we as need.

Functions can do one other thing too: they can give back a value to the place where they were called from. For this we use the special word return. For example, let’s see what a function to pick the largest of two numbers, we’ll call it Max(), might look like:

function start(){
    let a = 4;
    let b = 10;
    let c = Max(a, b);

function Max(n1, n2){
    if (n1 > n2)
        return n1;
        return n2;

We give Max() the two numbers we are comparing. If the first one is bigger than the second, it gives back the first. Otherwise, if gives back the second. Note too that the names of the variables in Max() are different to those in start(), and that’s not a problem.


Finally, we looked at the P5 function random(). We used it two different ways:

random(); // gives a number between 0...1
random(n); // gives a number between 0...n (where n is a number!)

In the first form, we used it to pick a random colour. In the second, we used it to pick a random position for our squares.


As usual, all the code is on the creators github repository. Head there and download it!! The files for this week contain both the script we wrote (sketch.js) and a longer version that I wrote (sketch2.js). Feel free to take a look at both!

Congratulations to all our ninjas who received belts in Summer 2017!

This slideshow requires JavaScript.

On 27 May 2017, at our final CoderDojo Athenry session of the 2016-17 year, we awarded a total of 93 belts to our ninjas for their great individual achievements in acquiring and demonstrating coding and computing skills. And then we had a party with pizza!

Here is a link to our presentation from the day: CoderDojo Athenry Belts Day 2017

We are very grateful to Clarin College Athenry and the principal, Ciaran Folan, for their enabling CoderDojo Athenry by making the school and its wifi available to us.

We are also very grateful for the sponsorship and support we have received this year:

  • Galway Roscommon Education and Training Board, who provide us with an annual Youth Club Grant
  • Medtronic, employer of our mentor Declan Fox, who provide us with a grant to match Declan’s excellent volunteering
  • HP Enterprise, employer of our mentor Mark Davis, who provide loaner laptops that we make great use of
  • Boston Scientific, employer of our mentor Kevin Madden, who provided us with a set of 3D printers this year, which allowed a great new learning experience

Because of these supports, no child or parent/guardian ever has to pay to participate in CoderDojo Athenry.

This year also, mentor Martha Fahy introduced a new idea, “Java Dojo”, where parents can buy a cup of tea/coffee, providing additional funds. With these, we have been able to buy a speaker system, electronics needed by some of our groups, and our own 3D printer! Thank you, our CoderDojo ninja sidekicks!

And of course we must thank our mentors, who volunteer their time and expertise entirely without charge week after week, to make CoderDojo Athenry the success that it is.

Here is the full list of belts we awarded:

  • Explorers:    44     (39 Yellow & 5 White)
  • Advancers:  18
  • Bodgers:     17
  • Hackers:      8
  • Creators:     5
  • Black Belt:   1

Special mention must go to Eoin Clarke, who received our first ever black belt award. Eoin has been in CoderDojo Athenry for several years, working his way up through the groups, and this year took on the role of Mentor. Well done, Eoin!

Above are some photos of the belts awarded. You can find more on our Facebook page:

CoderDojo Athenry is now closed for the summer. See you all in September!

Creators: Text Based Adventure

The last two weeks we were looking at something quite different: a text-based adventure system built in Unity. This was inspired by the Henry Stickmin games and also by the old 80s-style choose-your-own-adventure books.


Basic Program Design (Story Card)

The user is presented with a “story card”. A card consists of some text describing their current situation and (normally) a number of options to choose from.

Screen Shot 2017-04-05 at 14.12.23.png

Depending on which option they pick, the story branches from there, card-by-card, until it reaches an end (a card with no options).

Setting up a card is straightforward:

Screen Shot 2017-04-05 at 14.15.27.png

You enter the card description (the text the user sees on screen), the text that the user will see on each option button (the program supports up to four at the moment) and the card (or branch, but we’ll get to that later) to jump to when that option is selected.

There’s also the mention of “States to Set True/False” and we’ll explain that next.

Story States & Story Branches

We could have programmed the system entirely using only cards, but there’s one situation where this becomes tedious. Imagine that you have a choice; hitting a button for example. The consequences of this choice won’t become apparent until later in the story. If we only had story cards, then we’d have to branch the story immediately at his point, replicating the same steps on both branches until the point at which the consequences of your action played out.

Fortunately, there is a better way.

First, to remember the value we introduce the idea of a “story state’. It’s just a container for a true or false value. Cards can set the value of specific states when they are activated as seen above.

Screen Shot 2017-04-05 at 14.14.09

So, that covers remembering values, how do we then make use of them? This requires a “story branch”. A branch references a state and two places for the story to go (either of these can be a card or another branch). The value of the state determines which is picked.

Screen Shot 2017-04-05 at 14.19.01


Game Manager

This class looks after the story. It is responsible for updating the UI to the details of the current card, for handling the use clicking on specific buttons and generally directing the flow of the story. It also needs a StoryCard to start off the story with.

Screen Shot 2017-04-05 at 14.21.33.png



The project, including a very simple story using a number of cards and also a couple of states, can be found here. There are two scenes in the project, Adventure which contain a simple story and Basic which is a good starting place for your own story.

Creators : Breakout / Mouse Controlled Camera

Screen Shot 2017-03-16 at 15.25.41

This week we looked at a version of the classic game Breakout. It was an exercise in showing how a game developed with 3D assets can, nevertheless, appear like a 2D game given the correct choice of camera and lighting.

The camera for this game is an orthogonal one. Unlike a standard perspective camera, which mimics how we actually see the world, things don’t get smaller as they get further away with an orthogonal camera. This gives a very flat look where we don’t see the edges of the game area, blocks, bat or puck. In addition, the scene has a single directional light which shines directly downwards. Shining straight down means there are no shadows around the sides of the objects as there would be if the light was at an angle.

This game does not use Unity’s physics for the puck movement. I found that the physics just didn’t give the consistent behaviour you’d expect from this game. Accordingly, I programmed the movement of the puck myself. The maths is a little more complex than I’d like but the intention is to keep the puck moving at a constant speed, even after it hits something.

Additionally, we worked quickly on implementing a mouse controlled camera. In the hierarchy, we created a camera rig from two empty objects, one inside the other, and put the camera object inside the second. Changing the Y rotation of the first empty then turned the camera around the vertical while changing the X rotation of the second tilted the camera around horizontal. The visual below show what a real world camera rig that behaved this way might look like; rotating at the base and at a horizontal pivot.

Screen Shot 2017-03-16 at 15.53.28

In our scripts we referenced the usual horizontal and vertical input axes:

     float horiz = Input.GetAxis ("Horizontal");
     float vertical = Input.GetAxis ("Vertical");

but in the Input Manager (Edit|Project Settings|Input) we switched these from the arrow keys to the mouse axes:


Screen Shot 2017-03-16 at 15.35.08 (Edited)

The Breakout project can be downloaded here and the mouse controlled camera project can be downloaded here. These projects are both saved with Unity 5.5.2f1, so please use that version or later when opening them.




Creators – Projects


This week we spoke about possible projects. We also looked at games that you like so that we could draw inspiration from them.

When it comes to projects, there are a few questions you need to ask yourself:

What is the type of game you want to make?

Take a look here for an exhaustive list of game genres:

What is the setting for your game? Do you have a character in mind?

These choices will determine the look and tone of your game and are good things to decide early on.

What do I already know that will help create my game?

From what we’ve seen already this year, what things will your game need that you already know how to do?

What do I not yet know how to do?

There are things you might like to be able to do that you’re not sure about how to achieve; these are things to raise with your mentor. He’ll focus on these in the next few weeks. Also; check the Asset Store. There are many free things there that might help you complete your game. If you’d ultimately like to do everything yourself, look at these as items as placeholders to get the basic game working that you might eventually replace.

Finally remember:


You will find it hard to get time to work on your project and it’s your first project on your own in most cases. The most important things are to show something that is yours and something that is fun. Showing something that is overly complex but that is not fun is not as good.

Get your thinking caps on!

Creators – Unity Terrain

Screen Shot 2017-01-31 at 22.17.05.png

This week we looked at the Environment asset pack and the creation of terrains.

Terrains are, at their core, nothing more than a grayscale image (shades of black & white) where the colour values are interpreted as representing heights. Black is is interpreted as zero height, white is interpreted as maximum height (as defined in the terrain’s properties) and every shade of grey in-between represents an intermediate value. The terrain editing tools provides brushes in a variety of shapes to raise or lower the terrain as desired.

Terrains in Unity don’t just allow us to define their heights. They also allow the painting of the terrain with a combination of different textures. In the Environment asset pack there are a selection of useful textures for painting a natural looking environment. These are a grass texture, several rocky textures and a sand texture.

Screen Shot 2017-01-31 at 22.18.36.png

Trees and grass are also enclosed in the Environment asset pack. These are also painted onto the texture with a brush, or in the case of trees, autofilled to a requested total number.

Once we had our terrain built, we added a character controller from the Controllers asset pack to enable us to walk around in it. We finished the session experimenting with the water prefabs that come with the Environment pack.

Please note that I won’t be at Dojo next Saturday (4th Feb 2017). Nonetheless, you are welcome to attend and join another group for the day if you wish to do so.