- Home /
Can someone please explain
Hi, Could someone please explain the meaning of this
for (int i = 0; i < 3; i++)
and this
Player p = new Player(i, faction);
Can you give us the full code sample where your snippets came from? (the whole functions)
Answer by sparkzbarca · Dec 10, 2012 at 04:21 AM
for(...) its a loop. it does the same thing over and over
int i = 0
int is an integer. A whole number. variables have to have a type so you can know what you can do with them.
i is a variable. A variable is a name which stands for something. Like in math E = MC^2 or y = mx + b
i<3
while i is less than 3
i++
shorthand for i = i + 1;
so
i = 0 while i less than 3
i = i + 1
that is a loop that does whatever is in the loop 3 times
for (int i = 0; i < 3; i++) { print i; }
prints 0 1 2
Player p
player is a type again it tells you what you can do with a variable.
Player is a class. Classes are basically a collection of functions.
for example the integer class has the add function. the subtract function. the multiply and divide.
the string class (a string is a collection of characters. a character is a single keystroke) might have that as well but for example "a string" + "another string" should probably result in "a string another string". adding numbers creates a whole new number. 1 + 2 isnt 12 but it is with strings. Thats why the program needs to know what type a variable is. So when you write A + B it knows what to do.
new is a special word. it creates space in memory thats all.
player creates a a new player with some conditions.
You need to really learn how to program to understand this though. Pick up a C# or C++ book or download one or find a tutorial. Takes like a week or 2 to get the jist of it.
Best of luck
Your answer
Follow this Question
Related Questions
Trying to disable the Script below on trigger or the closest thing 0 Answers
How to use 1 animation controller for a character and an animated object ? 2 Answers
Simple - Visual Studio Code not loading script when icon is clicked through unity *Video provided* 0 Answers
Can anyone help me in Bolt 0 Answers