Global Variables and Local Variables. - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html) +---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html) +---- Thread: Global Variables and Local Variables. (/thread-9325.html) Pages:
1
2
|
RE: Global Variables and Local Variables, God Damn! (sorry) - JoeBradleyUK - 07-25-2011 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? RE: Global Variables and Local Variables, God Damn! (sorry) - DRedshot - 07-25-2011 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. RE: Global Variables and Local Variables, God Damn! (sorry) - JoeBradleyUK - 07-25-2011 Right, I get that part of it now RE: Global Variables and Local Variables, God Damn! (sorry) - JoeBradleyUK - 07-25-2011 (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) 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? RE: Global Variables and Local Variables, God Damn! (sorry) - DRedshot - 07-25-2011 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 RE: Global Variables and Local Variables, God Damn! (sorry) - JoeBradleyUK - 07-25-2011 All I need to know now is where to script this RE: Global Variables and Local Variables, God Damn! (sorry) - DRedshot - 07-25-2011 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. RE: Global Variables and Local Variables, God Damn! (sorry) - JoeBradleyUK - 07-25-2011 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? RE: Global Variables and Local Variables, God Damn! (sorry) - DRedshot - 07-25-2011 1. AddLocalVarInt adds the value which is already there, rather than set it. lets say the value is 3, SetLocalVarInt("Value" , 2); will set that value to 2, Whereas AddLocalVarInt("Value" , 2); will add 2 to the value, making it 5 2. Global variables are very similar to Local variables, the only difference is that they can be used between multiple maps, and they require their own .hps file to run, callsed global.hps This file should be located in exactly the same folder as your other .hps files, (such as maps and inventory.hps) the contents of this file look like this: void OnGameStart() { // Add/Set your global variables here } The problem with the global.hps, it that you cannot use functions like AddEntityCollideCallback, or AddUseItemCallback, they simply wont work i don't even know if you will get an error. you should use these functios only in your map.hps AddGlobalVarInt("" , ); and SetGlobalVarInt("" , ); work just like AddLocalVarInt("" , ); and SetLocalVarInt("" , ); also side note: AddLocalVarString("String" , "hi"); will add "hi" onto the end of the local variable, so if the LocalVariable was "hello", it will become "hellohi" RE: Global Variables and Local Variables, God Damn! (sorry) - JoeBradleyUK - 07-25-2011 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 |