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
#9
RE: Global Variables and Local Variables, God Damn! (sorry)

(07-24-2011, 12:53 AM)Apjjm Wrote:
(07-23-2011, 11:50 PM)JoeBradleyUK Wrote: Ok, the responses have made it a little better to understand, I don't know why but I can't seem to understand them fully! I understand the concept, it's just the actual scripting, say if I wanted a script area to only work once I have done something, would I make it so the set variable is 1 and when you go into the area it adds 1 which would activate that area? Is it kind of like that? Or am I wrong?

In that case, variables would be surplus to requirements. You would set up your first action to activate the area, which triggers something.

Variables would be required, if, say, you wanted to track the state of multiple things. To put it less abstractly, lets say your map is just a big long staircase. At the foot of the staircase is the entrance & exit door. At the top is a room with one table, on which is say, a golden relic item. You want it so that when you grab the relic a giant boulder is activated when you go halfway down the stairs. We don't want the relic in the inventory though, because we won't be jamming it into some cogs to solve a puzzle.

Obviously, this can be achieved by activating a script area placed over the stairs after getting the relic, and that is all that needs to be done.

However, lets say that this time, at the top of the stairs there is a slightly larger room instead. This room has 3 relics (or 4, or 5, or whatever relics). You only want the ball the trigger after 3 have been collected. Now is when you want to use variables. Furthermore, we shall assume that this "relic count" is stored for use later (say, in appeasing a deity so that he opens a door to his church for you).

From this problem we can decide one global variable, counting how many relics we currently have, is required. As scripted variables default to 0, we do not need to initialise this variable - 0 seems the best place to start counting. Our solution, then, would look as follows:

//The staircase & room map\\
void OnStart()
{

  //Step #1: Add an interact callback for each of our relics & trigger
  //Our relics are called relic_1, relic_2, relic_3.
  for(int i =1; i<=3; i++) SetEntityPlayerInteractCallback("relic_"+i,"cbRelicGrab",false);

AddEntityCollideCallback("Player","ChaseTrigger","cbChaseBegin",true,1);
}

void cbRelicGrab(string &in asEntity)
{
   //Step #2: The player has grabbed a relic. Increment the relic count!
   AddGlobalVarInt("RelicsTaken",1);
   //Stop the player grabbing the same relic over and over - deactivate this on.
   SetEntityActive(asEntity,false);
   //Are all the relics grabbed? Yes: Activate the chase trigger.
   if(GetGlobalVarInt("RelicsTaken") >= 3) SetEntityActive("ChaseTrigger",true);
}

void cbChaseBegin(string &in asParent, string &in asChild, int alState)
{
   //Step #3: GIANT ENEMY BOULDER!
   SetEntityActive("GiantBallOfDoom",true);
}

//Church of Deity Map:\\

void OnStart()
{
//Add a collision to a script area before the door to unlock if
//The deity is pleased with our offering of relics.
AddEntityCollideCallback("Player","DeityDoorTrigger","cbUnlockDoor",false,1);
}

void cbUnlockDoor(string &in asParent, string &in asChild, int alState)
{
//Has the player got all 3 relics?
if(GetGlobalVarInt("RelicsTaken") >= 3) SetSwingDoorLocked("BigSwingDoor",false,true);
}

Ok, i get it now, but the only thing i don't understand is this bit of the script Huh
//The staircase & room map\\
void OnStart()
{

  //Step #1: Add an interact callback for each of our relics & trigger
  //Our relics are called relic_1, relic_2, relic_3.
  for(int i =1; i<=3; i++) SetEntityPlayerInteractCallback("relic_"+i,"cbRelicGrab",false);

AddEntityCollideCallback("Player","ChaseTrigger","cbChaseBegin",true,1);
}

:Work In Progress:
Insanity
07-24-2011, 01:55 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 JoeBradleyUK - 07-24-2011, 01:55 PM



Users browsing this thread: 1 Guest(s)