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.
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#6
RE: Global Variables and Local Variables, God Damn! (sorry)

First, an overview:

Scripted Global variables:
  • Are stored in the save file, and carry between ALL maps.
  • Are used by using GetGlobalVar<Type> and SetGlobalVar<Type>
  • Names are passed into the above functions as a string
  • Default to 0 (or ""), and are created dynamically so can be used without an initialisation.
Scripted local vars
  • Are stored in the save file, but only apply to one map.
  • Are used by using GetLocalVar<Type> and SetLocalVar<Type>
  • Names are passed into the above functions as a string
  • Default to 0 (or ""), and are created dynamically so can be used without an initialisation.
Angelscript vars
  • Defined by placing the type (e.g: int, string, float, uint) followed by an identifier.
  • Are the stuff which can be passed into functions and the like
  • Are not saved, or transferred between maps.
  • The scope (I.e: how many {'s in it is) determines what can access it
  • Must be defined before use.

So, how can we use each one?
//Local vars
void RandomRoutine1()
{
   //Assignment
   SetLocalVarInt("variable_name",1234);
   SetLocalVarString("RandomVaraible_1","Yo dawg!");
  
   //Appending / adding
   AddLocalVarInt("variable_name",1);
   AddLocalVarString("RandomVaraible_1","I heard you like strings!");

   //Retreving
   int x = GetLocalVarInt("variable_name");
   string y = GetLocalVarString("RandomVaraible_1");

   //X now has the value 1235 (1234 + 1)
   //Y now has the value "Yo dawg!I heard you like strings!"
}

//Global vars work similarly. Take for example, using a score variable
//to chose which ending the player gets

void OnGameStart()
{
   SetGlobalVarInt("PlayerScore",1); //Initialise global score
  }

void somewhereOnAnylevel()
{
  AddGlobalVarInt("PlayerScore",1); //Add 1 to global score var
}

void somewhereAtEndOfGame()
{
   switch(GetGlobalVarInt("PlayerScore"))
     {
       case 0: {badEnding(); break;}
       case 1: {mediumEnding(); break;}
       case 2: {goodEnding(); break;}
       default: {hackerEnding();}
     }
}
(This post was last modified: 07-23-2011, 10:17 PM by Apjjm.)
07-23-2011, 10:15 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 Apjjm - 07-23-2011, 10:15 PM



Users browsing this thread: 1 Guest(s)