Frictional Games Forum (read-only)

Full Version: void OnStart() void OnEnter()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Can someone explain me the differences between the void OnStart() and the void OnEnter()? I know that void OnStart() is called when the player start a map for the first time. But what is the void OnEnter()? Where is the player entering? Thanks.
OnStart is one time only as you described, onEnter happens every time the player enters/re-enters the map (i.e. a hub scenario)
(10-13-2012, 11:51 PM)andyrockin123 Wrote: [ -> ]OnStart is one time only as you described, onEnter happens every time the player enters/re-enters the map (i.e. a hub scenario)
So let's say that I want that when the player enters the map for the first time something happen. Then he leaves. And now he re-entered the map. How do I control in which time the player enters the map, something will happen? Thanks for your reply.
You can use global variables with the "OnEnter" function to control when an event happens (i.e. perhaps the player gets another item from another map, or it's triggered just by how many times the player enters altogeter).

Here's a loop that adds a variable, and after the variable reaches x amount, it will trigger whatever script:

Spoiler below!

void OnEnter()
{
AddGlobalVarInt("var", 1);


if(GetGlobalVarInt("var") = 3)
{
///do stuff here
}
}


On the third time the player enters the map, it will activate the "do stuff here" part; this can be pretty much anything you'd want - setting up a callback, playing a sound, triggering a spooky event - anything.

Hope that helped!
This is a little hard to understand isn't it?
No, it isn't Wink

Let's say you have a map where you have a door and a key. The key opens the door. If the player leaves and everything was in OnStart(), when the player returns that key will be useless, because it was only usable the first time you went into the map. OnEnter () is more for "bug fixing".
(10-14-2012, 09:31 AM)The chaser Wrote: [ -> ]No, it isn't Wink

Let's say you have a map where you have a door and a key. The key opens the door. If the player leaves and everything was in OnStart(), when the player returns that key will be useless, because it was only usable the first time you went into the map. OnEnter () is more for "bug fixing".
So OnEnter() will call the functions every time the player enters the map until I use some "if" statement?
It isn't necessary to use an "if". For example, a hub. You want that when you enter a map a quiet music sounds, like in the main game.

If you put in OnStart(), the music will only sound when you enter in that map, if you leave and enter another time the music won't sound.

If you use OnEnter(), the music will sound every single time you enter. If you leave and enter another time, the music will sound.

If you want to make more complicated things, go forward. Use "if"s if you need them.
(10-14-2012, 02:14 PM)4WalledKid Wrote: [ -> ]
(10-14-2012, 09:31 AM)The chaser Wrote: [ -> ]No, it isn't Wink

Let's say you have a map where you have a door and a key. The key opens the door. If the player leaves and everything was in OnStart(), when the player returns that key will be useless, because it was only usable the first time you went into the map. OnEnter () is more for "bug fixing".
So OnEnter() will call the functions every time the player enters the map until I use some "if" statement?
To explain Andyrockin's script: A variable is just a number that you can change. In the script, each time the "OnEnter" function is called, we increase the variable by 1. Then we check whether or not the variable is equal to 3. If it is, the game moves on to do whatever we specified inside the { } brackets.
Oooh ok ok, and what was the global variable thing? And the item thing too.
Pages: 1 2