Helper Files

From Frictional Wiki
< HPL3
Revision as of 21:56, 10 August 2020 by TiMan (talk | contribs) (Created page with "{{Hpl3ScriptingGuideMenuBasic}} {{shortPageTitle}} This article explains what helper files are and how to use them. == Introduction == When you're writing your script, you ca...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This article explains what helper files are and how to use them.

Introduction

When you're writing your script, you can find yourself ending up with a lot of code. If all this code is inside a single file, that can make things difficult to manage - whenever you want to add or change something, you have to pour through hundreds or thousands of lines of code looking for that one spot.

Also, what if you want to use some code that was written by someone else? Do you just copy their code and paste it into your own? What if they update their code, forcing you to find everywhere in your code that was updated and perform the update yourself?

As I'm sure you've surmised by now, there's an easier way. There's a special keyword that references a script file and “pastes” it on top of another file. This allows functions and other things to be called from that other file without requiring that the code is in the same place - the include keyword.

Using Helper Files

As the name suggests, we include external script files in our code, which allows us to call other functions from other files.

As you have noticed, there are several includes at the top of our map script file. Each include points to another script file, which are labeled as helpers, because they help us with performing common scripts and actions.

For example, if we want to use player related functions, we need to include “helper_player.hps”