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

//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);
}

What the for loop is doing, is it is executing the instruction "SetEntityPlayerInteractCallback("relic_"+i,"cbRelicGrab",false);" multiple times. What is happening is a counting variable called "i" is created, and set to 1. Whilst the counting variable is <=3, the above instruction is executed. At the end of doing the above instruction, "i" is increased. "i" is not a "scripted" variable.

As our relics are called "relic_1", "relic_2", "relic_3", and "i" has the values, 1, 2 and 3 in each iteration of the loop. The prefix "relic_" is common between all our relics - Hopefully you can see how this pieces together.

This is all the same as executing the following instructions.
SetEntityPlayerInteractCallback("relic_"+1,"cbRelicGrab",false);
SetEntityPlayerInteractCallback("relic_"+2,"cbRelicGrab",false);
SetEntityPlayerInteractCallback("relic_"+3,"cbRelicGrab",false);
(This post was last modified: 07-24-2011, 02:04 PM by Apjjm.)
07-24-2011, 02:02 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-24-2011, 02:02 PM



Users browsing this thread: 1 Guest(s)