check for first time (triggers)

Ok I really am wondering about this because I have no idea how it can be implemented:
This goes for triggers btw: How can I check to see if it’s the first time a player has entered that area or stepped on that trigger? For example: it’s the player’s first time going in the zone and a cutscene appears, but if it’s the second, third, etc time the cutscene wont play. How would I go about doing this?

Please reply! :frowning:

Make a script called GameZone that has a:

bool hasBeenVisited;

Add that to a trigger collider that defines the zone, and set the bool to true for that particular zone when the player hits the trigger.

Thanks for the reply! And the help! :smile:

But just wondering, what exactly is a bool? I’m kinda new to java scripting so I dont really know much but yeah lol. :stuck_out_tongue:

If you need “one-time triggers”, that really only need to be triggered once, and never reset, you can also simply destroy them when they’re done.

Yes that’s also what I had in mind. Thanks!

A bool (or boolean) value simply stores true or false (translates to 1 or 0) and is the simplest variable type.

for example:

var hasBeenVisited : boolean = false;


function EnterDungeon(){
  if (!hasBeenVisited){
    RunImpressiveCutscene();
    hasBeenVisited = true;
  }

  GetOnWithRestOfStuff();
}

Or, in C#:

private bool hasBeenVisited = false;

public void EnterDungeon(){
  if(!hasBeenVisited){
    RunImpressiveCutscene();
    hasBeenVisited = true;
  }

  GetOnWithRestOfStuff();
}

Oh ok thanks! :slight_smile:
So in my understanding, the variable is HasBeenVisited and says that it’s false (meaning that the zone has not just been visited) and if it’s the first time visited then play a cutscene. If not just continue normally. Right?

Now I’m also wondering (bit off topic) because I havent really figured this out but what is the difference between “{” and “}”?

Ah -

{ and } are like the beginning and end of a container. After the ‘if (something)’ statement, the code will execute the next line of code if (something) is true, and will skip over it if (something) is false.

Usually, of course, we want to do more than one thing after we check the value of (something). So instead, we write:

if (something)
{
 DoSomething();
 DoSomethingElse();
 KeepGoing();
 etc = etc + 1;
}

The curly braces say that all four lines belong with that if statement. If (something) is true, all four lines will be executed. If (something) is false, they’ll all be skipped.

The regular parentheses ‘(’ and ‘)’ wrap around the stuff that a function needs to do its job - so that’s where parameters for functions, if statements, loops, etc. will go.

Also, the ! in these two languages is the logical check for “not” - so if(!something) literally says “if not something”… So if “something” is true, then “not something” is automatically false, and vice versa. (You can only do that to boolean logic values).

In this case, (!something) is the same check as (something != true), or “something is not true,” and also to (something == false) or “something is false.”

Hope all this helps,

~D

Ohh ok thank you so much!