- variables
- functions
- objects
What is a variable?
A variable is nothing more than a small bucket you can store things to, like numbers, text, objects, lists, anything at all.
For example, every time you login into a website, the page requests your a user and password, and when you type them, your're writing that info into a "user" and a "password" variables respectively, so they can be read and validated.
What is a function?
While the variable is "storage" of data, a function represents a set of "actions" to take with or without that data.
Just like the login web page, when you press Enter or click in the submit button to confirm your credentials, you're actually calling a function to take the "action" to send that information over the network.
Functions can return new data or not return any data at all.
For example: in the case of the web page, it returns feedback in whether your login was successful or not.
So, in short: a variable is to store data and a function is the action to take (generally based on that data).
What is an object?
An object is something which holds a set of variables and functions within it. The web page itself is an object: it has the fields for you to fill in with data (user and password) and the button to send that data over (the submit function).
When variables are contained within objects they are also called: members, properties or attributes.
When functions are contained within objects they are also called (depending on their purpose):
- methods: when they do not return a value;
- getters: when their purpose is to return the value of one of that object variables;
- setters: when their purpose is to store a value in one of that object variables;
However, when they return new data, their correct name is still function.
You should start getting familiar with these terms, so whenever you read something on coding, you know what's being talked about.
Example:
- let's say you want to do a sum like 658 + 363 using paper alone.
You take the paper (the object), and fill it with the numbers (the variables):
Code: Select all
658
+ 363
------
Code: Select all
1 11 11
658 658 658
+ 363 > + 363 > + 363
------ ------ ------
1 21 1021
Now here's the same example, but translated into UnrealScript:
The variables and functions within the object:
Code: Select all
class Paper extends Object;
var int FirstNumber;
var int SecondNumber;
function int getSum(int A, int B)
{
local int result;
result = A + B;
return result;
}
Code: Select all
getSum(FirstNumber, SecondNumber);
Code: Select all
sumVar = getSum(FirstNumber, SecondNumber);
Homework:
Based in what you learned so far, create a new mutator which can count the number of player respawns during the whole match, and in each player respawn, broadcast a message to all players with that number.
[ The code with the solution will be posted in the next lesson under spoiler tags, however it is highly encouraged to do it without looking at the solution. ]
From here onwards, all the lessons will be about UnrealScript itself and its structure as a coding language, or in other words: the warm up is finally over, and it's time to cover how the language and Unreal Engine works for real from now on.
Also, I will be posting more of these "homeworks" from now on so you can start to develop your own programming skills in order to understand things more independently.
________________________________________________________________________________________________________________________