Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Global Variables and Local Variables.
JoeBradleyUK Offline
Member

Posts: 115
Threads: 20
Joined: Jul 2011
Reputation: 0
#14
RE: Global Variables and Local Variables, God Damn! (sorry)

(07-25-2011, 01:48 AM)DRedshot Wrote: you've almost got it right. the 'for statement' creates multiple instances of i, (from 1 to 3 in this case)

this is specified in the brackets: - for(int i=1; i<=3;i++){ // code }
break it down to:
for - run the code at the end a set number of times
int i=1 - the first value of i=1
i<=3 - i cannot be greater than three, it must be lessthan or equal to three
i++ - 1 is added to i

so at first i = 1; this means that (i <= 3), so the code at the end runs with int i = 1
second i++ is run, so now i = (i + 1), so i = 2
i = 2; this still means i <= 3, so the code at the end is run again, but this time with int i = 2
i++ again so i = 3
i = 3, i is still <= 3, so code runs again but this time int i = 3;
i++ (i = 3 + 1) so i = 4
i = 4, i is now > 3; so the for loop terminates.

i itself can be carried over to the code executed by the 'for statement' which is why in the previous code it says something like ("Relic_"+i) this is the equivalant of writing:
("Relic_1")
("Relic_2")
("Relic_3")

to answer some of your questions:

i does not always equal 1, it increases from 1 to 3
You do not set i = 1, yiou make i = (anything between and including 1 and 3)

i++ basically adds 1 to the current value of i

I hope this helped you out, i'm not really great at explaiing things, also, if i've mislead in anyway, or you don't quite understand, just ask.
Also, i know i never answered all your questions, so maybe someone else can help clear those up.

Wait, is this stuff to do with i's and things even essential/needed to do variables?
What I mean is can you do three individual callbacks but keep the variables down below, if you get me?

:Work In Progress:
Insanity
07-25-2011, 11:19 AM
Find


Messages In This Thread
RE: Variables, God Damn! (sorry) - by xtron - 07-23-2011, 08:59 PM
RE: Global Variables and Local Variables, God Damn! (sorry) - by JoeBradleyUK - 07-25-2011, 11:19 AM



Users browsing this thread: 1 Guest(s)