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.
DRedshot Offline
Senior Member

Posts: 374
Threads: 23
Joined: Jun 2011
Reputation: 11
#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. Smile


07-25-2011, 07:08 PM
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 DRedshot - 07-25-2011, 07:08 PM



Users browsing this thread: 1 Guest(s)