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
Script Help Questions on scripts and script placement.
GoreGrinder99 Offline
Member

Posts: 166
Threads: 47
Joined: Feb 2013
Reputation: 1
#1
Questions on scripts and script placement.

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?

-Grind to the Gore-
08-17-2013, 12:16 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#2
RE: Questions on scripts and script placement.

(08-17-2013, 12:16 AM)goregrinder99 Wrote: Can't all scripts be placed in either of the 3 On* functions?

Sure, but that wouldn't make any sense. For example, why would you want to preload sounds and particles, or play music, etc, in OnLeave?

(08-17-2013, 12:16 AM)goregrinder99 Wrote: Could I get a simple list of what "belongs" where, in the OnStart, OnEnter, OnLeave and OnGameStart?

inventory.hps and global.hps uses OnGameStart. HPS files that are linked to map files use OnStart, OnEnter and OnLeave.

Tutorials: From Noob to Pro
08-17-2013, 12:43 AM
Website Find
The chaser Offline
Posting Freak

Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation: 113
#3
RE: Questions on scripts and script placement.

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

THE OTHERWORLD (WIP)
[Image: k6vbdhu]

Aculy iz dolan.
08-17-2013, 12:49 AM
Find
GoreGrinder99 Offline
Member

Posts: 166
Threads: 47
Joined: Feb 2013
Reputation: 1
#4
RE: Questions on scripts and script placement.

Thanks, fellas, greatly appreciated.

Still a little curious though... What majority of functions are used in the OnStart? I'm assuming all Callbacks, Variables and starting Player/Screen Effects (Say, for a wake-up). Any others?

Now, can all the callback syntax and other scripts like the Game Timers, Quests, Journals and whatever, aside from the obvious OnStart scripts and OnLeave scripts, be placed into the OnEnter function?

-Grind to the Gore-
08-17-2013, 02:42 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#5
RE: Questions on scripts and script placement.

(08-17-2013, 02:42 AM)goregrinder99 Wrote: Still a little curious though... What majority of functions are used in the OnStart? I'm assuming all Callbacks, Variables and starting Player/Screen Effects (Say, for a wake-up). Any others?

Now, can all the callback syntax and other scripts like the Game Timers, Quests, Journals and whatever, aside from the obvious OnStart scripts and OnLeave scripts, be placed into the OnEnter function?

Playing music, preloading sounds and preloading particles should go in OnEnter.

Wake-up script should go in OnStart, unless you want it to repeat itself every time the player re-enters the map. Same goes for callbacks and map variables (i.e. variables declared with SetLocalVar* and SetGlobalVar*). But if you're just declaring map variables, then OnStart is the proper place.

You should note, though, that a callback can still loop if placed in OnStart, you just have to pay attention to how you set up your callbacks.

Tutorials: From Noob to Pro
08-17-2013, 03:11 AM
Website Find
GoreGrinder99 Offline
Member

Posts: 166
Threads: 47
Joined: Feb 2013
Reputation: 1
#6
RE: Questions on scripts and script placement.

(08-17-2013, 03:11 AM)Your Computer Wrote:
(08-17-2013, 02:42 AM)goregrinder99 Wrote: Still a little curious though... What majority of functions are used in the OnStart? I'm assuming all Callbacks, Variables and starting Player/Screen Effects (Say, for a wake-up). Any others?

Now, can all the callback syntax and other scripts like the Game Timers, Quests, Journals and whatever, aside from the obvious OnStart scripts and OnLeave scripts, be placed into the OnEnter function?

Playing music, preloading sounds and preloading particles should go in OnEnter.

Wake-up script should go in OnStart, unless you want it to repeat itself every time the player re-enters the map. Same goes for callbacks and map variables (i.e. variables declared with SetLocalVar* and SetGlobalVar*). But if you're just declaring map variables, then OnStart is the proper place.

You should note, though, that a callback can still loop if placed in OnStart, you just have to pay attention to how you set up your callbacks.

Item Interactions and Collide Callbacks should always be placed in OnStart?

-Grind to the Gore-
08-17-2013, 04:27 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#7
RE: Questions on scripts and script placement.

(08-17-2013, 04:27 AM)goregrinder99 Wrote: Item Interactions and Collide Callbacks should always be placed in OnStart?

As i said, that depends on what you want to accomplish. The functions used to set up callbacks tend to allow you to declare whether or not you want that callback to remain after triggering it. OnStart gets called once for each new session of the map. (Loading a save is not a new session, and so it doesn't get called then.) OnEnter gets called every time the map is loaded outside of saves. All of this means there is one point in time where OnStart and OnEnter are both called, but every other time only OnEnter would be called.

Tutorials: From Noob to Pro
08-17-2013, 04:49 AM
Website Find
GoreGrinder99 Offline
Member

Posts: 166
Threads: 47
Joined: Feb 2013
Reputation: 1
#8
RE: Questions on scripts and script placement.

(08-17-2013, 04:49 AM)Your Computer Wrote:
(08-17-2013, 04:27 AM)goregrinder99 Wrote: Item Interactions and Collide Callbacks should always be placed in OnStart?

As i said, that depends on what you want to accomplish. The functions used to set up callbacks tend to allow you to declare whether or not you want that callback to remain after triggering it. OnStart gets called once for each new session of the map. (Loading a save is not a new session, and so it doesn't get called then.) OnEnter gets called every time the map is loaded outside of saves. All of this means there is one point in time where OnStart and OnEnter are both called, but every other time only OnEnter would be called.

So either way when you load a save, callbacks are negated and no longer in effect? Not sure if I'm getting this... -_-

Say I have an AddEntityCollideCallback and an AddUseItemCallback. What would be the effect of having them in the OnStart or the OnEnter function?

If I open the game and save right away and load it up, will the callbacks still take effect when I either hit the collide area or try to unlock a door with a key if the scripts are set in the OnStart or OnEnter or both?

-Grind to the Gore-
08-17-2013, 05:56 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#9
RE: Questions on scripts and script placement.

(08-17-2013, 05:56 AM)goregrinder99 Wrote: So either way when you load a save, callbacks are negated and no longer in effect? Not sure if I'm getting this... -_-

Say I have an AddEntityCollideCallback and an AddUseItemCallback. What would be the effect of having them in the OnStart or the OnEnter function?

If I open the game and save right away and load it up, will the callbacks still take effect when I either hit the collide area or try to unlock a door with a key if the scripts are set in the OnStart or OnEnter or both?

When you specify to the engine not to remove the callback after triggering it, the callback remains in the session. This means when the user saves their progress, the callbacks get saved, too, in the save file. So when the user loads a save, the callbacks get loaded too, therefore OnStart and OnEnter are not required to initiate the callbacks again. Same goes for timers.

Tutorials: From Noob to Pro
(This post was last modified: 08-17-2013, 10:10 AM by Your Computer.)
08-17-2013, 10:08 AM
Website Find




Users browsing this thread: 1 Guest(s)