Frictional Games Forum (read-only)
void OnStart() void OnEnter() - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: void OnStart() void OnEnter() (/thread-18766.html)

Pages: 1 2


void OnStart() void OnEnter() - 4WalledKid - 10-13-2012

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.


RE: void OnStart() void OnEnter() - Adny - 10-13-2012

OnStart is one time only as you described, onEnter happens every time the player enters/re-enters the map (i.e. a hub scenario)


RE: void OnStart() void OnEnter() - 4WalledKid - 10-14-2012

(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.


RE: void OnStart() void OnEnter() - Adny - 10-14-2012

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!


RE: void OnStart() void OnEnter() - 4WalledKid - 10-14-2012

This is a little hard to understand isn't it?


RE: void OnStart() void OnEnter() - The chaser - 10-14-2012

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".


RE: void OnStart() void OnEnter() - 4WalledKid - 10-14-2012

(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?


RE: void OnStart() void OnEnter() - The chaser - 10-14-2012

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.


RE: void OnStart() void OnEnter() - MyRedNeptune - 10-14-2012

(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.


RE: void OnStart() void OnEnter() - 4WalledKid - 10-14-2012

Oooh ok ok, and what was the global variable thing? And the item thing too.