Fluttermind
  • news
  • games
  • music
  • contact
  • press kit

Coding for Beginners #1: Ingredients

4/1/2022

2 Comments

 

Introduction

Congratulations! You clicked on a link to something a lot of people consider to be well beyond their ability. Rumours of complex maths, arcane syntax and a host of other scary things put people off attempting to learn to code. This is a shame because even an idiot can learn to code. I am a living example of that.

My goal here is to prove that if you can write a sentence, you can code.
In fact, that last sentence was practically code in itself!
a = "Can write a sentence"
b = "Can write code!"
c = "Can't write code!"
if a == "Can write a sentence" then
  print(b)
else
  print(c)
​end

If you want to try this for yourself, you can go to the web-page here and type this into the box on the left, and then click 'execute'. If you type it exactly as shown (or cut-and-paste like a stinky cheater), you'll see the result:

     "Can write code!"

If you tried that out, then you've proven my point: you just wrote code, you didn't die, and your brain didn't explode. Congratulations!

So What is Coding?

Coding is much like baking. You take ingredients, do stuff to them in a defined order, and end up with (something hopefully similar to) a cake. In the case of coding, those 'ingredients' are data: keyboard input, joystick buttons, text, an image, or anything else. Likewise, the output can be anything you want: a song, a game, or a piece of text.

Ingredients/Variables

In the example above, we had the line: 

    a = "Can write sentence"

The 'a' is a 'variable'. It's like a label on an ingredient box that can contain anything at all. We use variables to store data and then perform operations on that data to get outputs we want. 

The '=' sign pushes the words "Can write a sentence" into the ingredient box labelled 'a'.

After this, 'a' contains the words "Can write sentence".

If we had typed:

    a = 10

...then the variable 'a' would contain the number 10 rather than "Can write a sentence". A variable doesn't care what it contains. The variable is just a label. If you used a shoe-box and labelled it 'old DVDs' the world wouldn't end if you decided to fill it with socks, even though you might be confused on the day you move out.

Also note that, like any label, what we chose as a label for the variable was entirely arbitrary. The letter 'a' has no significance at all. We could have written this instead:

    hedwig  = "Can write sentence"

The computer doesn't care what we name things (unless the name clashes with something else). We're just creating a label so that when we want to do something to that variable/data, we can refer to it in a sensible way.

In this case...

    print(hedwig)

...will output "Can write a sentence" because we previously 'assigned' (filled) the box labelled 'hedwig' with those words.

Note that it does not output the word hedwig, because the computer only cares about the contents of the data with that label, not the label itself.

Conclusion

Today, you learned about variables (the ingredients of your code). 
Next time we'll learn how to do more things with those variables.
​
I hope this was simple and informative and that you'll join me for the next one!

Good luck and ask any questions you want here.
2 Comments
Mark
4/6/2022 09:37:08 am

As an aside - is it worth adding that if you use quotes within the print brackets (or whatever they are called), so print("hedwig") it would then print hedwig

Reply
Mark again
4/6/2022 09:41:08 am

ahhhh - chapter 3 ;)

Reply



Leave a Reply.

    Author

    Fluttermind’s director, Dene Carter, is a games industry veteran of over 25 years, and co-founder of Big Blue Box Studios, creators of the Fable franchise for the XBox and XBox 360.

    Dene takes great pride in doing every aspect of game-creation entirely by himself. Nobody knows why.

    Archives

    April 2022
    March 2019
    April 2018
    January 2018
    February 2017
    September 2016
    July 2016
    February 2016
    October 2015
    June 2015
    February 2015
    January 2015
    November 2014
    April 2014
    March 2014
    February 2014
    January 2014
    November 2013
    August 2013
    May 2013
    February 2013
    December 2012
    November 2012

    Categories

    All

Powered by Create your own unique website with customizable templates.
  • news
  • games
  • music
  • contact
  • press kit