Frictional Games | Forum | Newsletter | Dev Blog | Dev Wiki | Support | Shelf | Store

• 0 Votes - 0 Average
• 1
• 2
• 3
• 4
• 5
 Solved Global Variables and Local Variables. Author Message
Member

Posts: 115
Joined: Jul 2011
Reputation: 0
 Post: #11 RE: Global Variables and Local Variables, God Damn! (sorry) Ok, I broke it down in my head, so what you're doing is making it so i = 1 or you could say i is less than three (i <=3) And in the callback everytime you pick up the relic it adds i which is the variable you set which equals 1. Once you get all three it makes sure you have 3 or more to active it Once you have enough it activates the trigger and whatever you want. If I am understanding that correctly, there are 2 things still I don't get: 1) Where to script each of the things 2) what does the i++ mean at the if variable thing? :Work In Progress: Insanity
07-25-2011 12:27 AM
DRedshot
Senior Member

Posts: 373
Joined: Jun 2011
Reputation: 11
 Post: #12 RE: Global Variables and Local Variables, God Damn! (sorry) 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. (This post was last modified: 07-25-2011 01:55 AM by DRedshot.)
07-25-2011 01:48 AM
Member

Posts: 115
Joined: Jul 2011
Reputation: 0
 Post: #13 RE: Global Variables and Local Variables, God Damn! (sorry) Right, I get that part of it now :Work In Progress: Insanity
07-25-2011 02:17 AM
Member

Posts: 115
Joined: Jul 2011
Reputation: 0
 Post: #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
DRedshot
Senior Member

Posts: 373
Joined: Jun 2011
Reputation: 11
 Post: #15 RE: Global Variables and Local Variables, God Damn! (sorry) yep, that is exactly what the for does, it makes multiple callbacks into one simple line of text. it is not essential and can be replaced with three lines of text
07-25-2011 12:53 PM
Member

Posts: 115
Joined: Jul 2011
Reputation: 0
 Post: #16 RE: Global Variables and Local Variables, God Damn! (sorry) All I need to know now is where to script this :Work In Progress: Insanity
07-25-2011 05:31 PM
DRedshot
Senior Member

Posts: 373
Joined: Jun 2011
Reputation: 11
 Post: #17 RE: Global Variables and Local Variables, God Damn! (sorry) ok so first you put SetLocalVarInt("What is the number" , 1); this sets the local variable - which is an integer, and has the name of "What is the number" to 1 then, later in the script you can use: if(GetLocalVarInt("What is the number")==1){ // run code} you can put SetLocalVarInt("What is the number" , 1); in any function you like, you could even put it in OnStart(). The most suitable place to put the variable would depend on what you want to do. Example: you have a hallway, halfway down you have a script area, called "Area_1", at one end of the hallway you have another area called "Area_2". If you want something to happen at "Area_1" if, and only if the player has stepped into "Area_2" previously, you could create two AddEntityCollideCallbacks, one for "Area_1" and one for "Area_2". When the player collides with "Area_2", you Set a Local Variable called "Name Here" to 1. in code this is written as: SetLocalVarInt("Name Here" , 1); This stores that value as 1. then when you collide with "Area_1", you put if(GetLocalVarInt("Name Here")==1){ // run spooky code} therefore when the player first collides with "Area_1", the local variable called("Name Here")==0, this is because by default it is 0. then when the player collides with "Area_2", it is set to 1. then the next time the player colllides with "Area_1", the local variable == 1, so the code executes.
07-25-2011 07:08 PM
Member

Posts: 115
Joined: Jul 2011
Reputation: 0
 Post: #18 RE: Global Variables and Local Variables, God Damn! (sorry) Ok I understand, what is the addlocalvarint for then? Is it if you want the person to do multiple things and something happen? Plus where would I script global vars and are global vars scripted the same as local ones? Except it being global not local? :Work In Progress: Insanity
07-25-2011 07:37 PM
DRedshot
Senior Member

Posts: 373
Joined: Jun 2011
Reputation: 11
07-25-2011 08:11 PM
Member

Posts: 115
Joined: Jul 2011
Reputation: 0
 Post: #20 RE: Global Variables and Local Variables, God Damn! (sorry) I can't express how happy I am. I understand variables now and now I can put them into my custom stories! Thankyou for all your help!! and everyone else's help :Work In Progress: Insanity
07-25-2011 08:18 PM
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)