Getting to grips with Variables

Geoff Newman
3 min readMar 24, 2021

Yesterday as I was discussing setting up player movement I said that I will get to explaining what are variables. Just like “x” in algebra, variables aren’t as scary as they first appear. A variable is just a container to store some type of data, that is as the name implies it is variable by design (same as “x” could equal 3 or 5, etc.).

There a many different types of variables available to a programmer in C# (or any other programming language) that as a developer you’ll use every day these main basic type

The first is int. this is short for Integer, now if it’s been a while since high school math an Integer is a whole number that is either positive or negative, so -2, -1, 1 & 2 are all Integers.

The next is float. Now a float just means it is a floating-point number (a decimal). if you look at the picture to the left this has something very different, you probably noticed the value of 2.5f. The f isn’t some fancy algebra it there so that C# knows it is a floating-point number. Why? I hear you ask that is because there are other decimal Types. The difference is size, a float is the smallest of the decimal Types, but seeing as seven decimal places that a float has is more than enough for 99.99% of values we need to store that other Types, Double (as the name suggests is double the size at 14 decimal places) and Decimal (29 places) are rarely ever used (I’ve never needed a Decimal).

Next of the everyday used Variables is bool. bool is short for Boolean. Booleans are simply true or false. The statement “It is Sunny outside” is either true or it is false.

The next most common type of variable is a string. Strings are just that a string of characters. so “The Fat Cat Sat on the Mat” is a string. In fact, the text of this article is just one big string.

In conclusion, Variables are containers in memory that store data whether they are a simple true or false to a sentence to display NPC dialogue or one of the many other Types available (which I’m sure I’ll go over before to long), Variables are a Game Dev’s bread and butter.

--

--

Geoff Newman

I am a technical Game Designer from Melbourne, Victoria, with Skills in Level design, C#, C++ and Unity.