Variables! — The building blocks of programming

Renato Figueiredo
2 min readNov 21, 2023

In order for us to properly learn how to code, we have to know what Variables are.

Think of a box, a specific box that can hold a value, which we can use it instead of having to call that specific value.

There are 3 required components, with an option 4th, for us to create a Variable.

This is an example of each of the 4 common type of data type variables.

We can see that for us to create a Variable, we need to know if its either Public or Private. This means, are other scripts supposed to know of the existence of this Variable ?

Data type, which tells us what kind of box we are going to use. We can’t store heavy items in a weak box. So the data type is making sure that you are assigning the right box for the job.

Every variable has a name, otherwise, how would we know what we are going to use ? Think of it as a person in this case, how would you call people if they didn’t have a name ? Makes it easier to control everything!

And lastly we have the value of the variable itself. This is option when creating the variable, although the example has a value for each created variable.

After we have all this information set, we are good to go in using our box.
Now we can simply call the variable by name, when we need, in order to access its value.

Debug.Log(wholeNumber);
Debug.Log(_floatNumber);
Debug.Log(isRenatoRight);
Debug.Log(_myName);
As we can see, the assigned value of each variable is shown now in the console.

Now we have all our information properly displayed on the console. Ever wondered how the game NPC always knew your name when you were speaking to him ? Its ’cause your name was stored in a variable, that is used on the text of the NPC, to chat with the player.

Lastly, when naming our variables, its a good practice to keep them in private, unless its absolutely needed to have them public.
Also, when creating a private variable, its best practice to start the variable name with a “_”, as shown in the example above.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet