(08-17-2013, 12:16 AM)goregrinder99 Wrote: First, a few quick questions.
What is the point to preload particles and sounds?
How are random floats and intigers used?
How are local and global variables used?
What are sticky areas and how are they used?
How do you use the auto save function script?
How do you use checkpoints in case the player dies for respawn?
Now that those are out of the way, I'd like to know what scripts are most often placed into the OnStart, OnEnter and OnLeave functions as well as the OnGameStart.
I have noticed that most of everything I have seen in the OnEnter is preload particles and sounds and loading images and text and on the OnLeave is stop sounds/music and loading images and text. I know that the majority of scripts are placed elsewhere for whatever reason but why? Can't all scripts be placed in either of the 3 On* functions?
Could I get a simple list of what "belongs" where, in the OnStart, OnEnter, OnLeave and OnGameStart?
void OnStart() means that what you put there will only be made the FIRST time you enter the level. OnEnter() means that what you out there will happen when you ENTER the level, and OnLeave() when you leave. In the latest one, it's usually used to stop any music or effect.
"What is the point to preload particles and sounds?"
Although I don't know how it works, preloading helps performance.
"How are random floats and intigers used?"
When you want something random you use them:
For example: We want to have a sound playing only in 1 of 4 areas, but we want it to play in a random area:
PlaySoundAtEntity("", "sound.snt", "Area_"+RandInt(1, 4), 0.1, false);
Integers are natural only numbers, like 1, 6, 12, etc. Floats are like 0.1, 2, 3.4, etc.
"How are local and global variables used?"
When you are making a more or less complicated code you usually use them, example:
"We only want the player to spawn a grunt if he hasn't picked up an item"
void OnStart()
{
SetLocalVarInt("Var", 0);
AddEntityCollideCallback("Player", "Area", "Grunt", false, 1);
SetEntityCallbackFunc("Item", "Pick");
}
void Grunt (string &in asParent, string &in asChild, int alState)
{
if (GetLocalVarInt("Var") == 1)
{
//Spawn grunt
}
}
void Pick (string &in asItem, string &in asType)
{
AddLocalVarInt("Var", 1);
}
"What are sticky areas and how are they used?"
The name tells you: They are sticky because they attract an object to them. I don't know much about them though.
"How do you use the auto save function script?"
No idea...
"How do you use checkpoints in case the player dies for respawn?"
http://wiki.frictionalgames.com/hpl2/tut...riptarea_s
void OnStart() is usually used for things that only happen once, like a cinematic level. void OnEnter() is where you want to put stuff that improves performance, because they will be used every time you enter the level. OnLeave, as you said, is stopping stuff because otherwise it would conflict with the other level you are entering in.
If you entered all of your events in void OnStart(), those events would happen only the first time you entered the level. If you entered the level and you left right at the moment, when you returned nothing would happen.
OnGameStart() is for the inventory.hps. There is where you put all the combinating callbacks.