Variables-Don’t Be A Rockstar

Mike Brisson
2 min readMar 27, 2021

--

It was 2013…both the PS3 and Xbox 360 were about to see new models, and GTA V had hit the shelves. It was a great time to be a gamer…unless you had earned more than $2,147,483,647 in game.

Rockstar had used an int variable type neglecting that players would inevitably surpass this amount. which in turn wrapped to the opposite end of the variable limit.

The result was that people ended up showing a negative value…an enormously negative number!

The answer to the question nobody asked: Could you write a program without any variables?…Technically, yes. Not only would you be compounding the number of lines of code needed to create simple tasks, but you would make troubleshooting bugs exponentially difficult.

Variables not only help you simplify your code, but they also can help optimize the performance of your program.

If you have ever written a C# program from scratch, you’ve likely had to write a variable in the first line of code:

The “args” in this case is an array of type string

The following are a list of the more common data types:

Choosing the correct type is usually simple. If you want a true/false, you pick bool…if you want a single character, you choose char.

In Unity, the 2 most numerically represented types are int and float. Int if you need whole numbers and float if you want a decimal point.

You may wonder why there so many options for numbers…why not just use the one that gives the widest range?

In a word…Memory. The larger the size of bytes, the larger the memory is needed and therefore the larger your program will be.

So what would happen if you used the smallest size, say int for example, and used that for all number variables, regardless of size? You can ask the developers at Rockstar what happened when they did this with the release of GTA V.

--

--

Responses (1)