Table of Contents

Script - Tutorial 1

HPL2 uses a script language called AngelScript, it is a C/C++ based syntax and a brief overview of the syntax can be found here.

I do not know how to script?!

Scripting in HPL2 is about as easy as it gets, without adding an extra help system (for example Blizzard has some very nifty tools in their editors to help with scripting). But even so it will be a mess and you will be lost with no previous experience. What you need is basically an introduction course to C/C++ or a script language based on that syntax, for example Javascript.

In my own experience, as a non-educated fellow in the world of scripting, I think you are best of taking a look at Javascript before you try to begin scripting in HPL2. Why? Because it is easy to find Javascript tutorials and information online and all you need is a text editor and your web browser. A place to start is for example w3schools introduction to Javascript. Mainly chapters JS Comments to JS For...In touch the general subjects that are common to all syntax's.

A short version is that all that you do in HPL2 is to use functions, they are commands that you give properties and then all the magic is taken care of by the game. Everything here are functions. You then decide how and when the functions are to be executed by using the common programing specific parts such as statements, variables and comparisons in combination with the objects you place using the level editor.

Example for those with no prior experience

Script is simplified and will not actually work ingame AT ALL, syntax is incorrect and only written as it is to give a short snippet of script code.

AddEntityCollideCallback("Player","AreaHelp","CollidePlayerWithAreaHelp");
 
void CollidePlayerWithAreaHelp()
{
    if(HasItem("cellar_key") == true)
    {
        SetMessage("Use your inventory to select key and use on door.", 10);
    }
    else
    {
        SetMessage("You will need a key to open the door.", 5);
    }
 
}

Imagine that, using the level editor, we have created a simple room. In this room we have a locked door and in front of that door we have added an area called “AreaHelp”. What we now have done in the script is that we have added a callback (a trigger if you so like), this is the line with AddEntityCollideCallback. It says that when the Player enters AreaHelp it should trigger the function CollidePlayerWithAreaHelp.

- When the player enters this area the function (begins with void CollidePlayerWithAreaHelp() and the rest of the script) is triggered and this occurs:

  1. It asks, does the player have the item “cellar_key” in his inventory?
    1. If this is true, we will then show a message on the screen for 10 seconds telling him what to do with the key.
    2. If this is not true, we show a message about where to find the key for 5 seconds instead.

This is all there is to it. Sure things will be more complicated and much longer, but the whole idea is always the same. When something occurs that you are looking for, you ask if something is the way you want it to, depending on what the answer is, you do different things. The tricky part will be to learn all the specific bits that you can do, what the game allows for, how to write something that affects many objects, but without doing it specifically for each (this is where variables comes in) and that sort of thing (always being logical is the key, but that is hard for a human (me)!). Imaging it as being a Swede and learning English:

You learn that “Flytta” can be “Move” in English, that you can Move an object, say a Rock, and that the Rock can be Moved at different Speeds. In HPL2 this would be a function you can call in the script, for example (again this does not really work):

MoveObject("Rock", 10); 

How this actually makes the rock move is not important, that is all taken care of by the game, but you have specified that you want to move a specific Rock and that is should be moved at a speed of 10 (this could be 10 m/s, but this is something you need to look up and learn and not something you specify). The only HPL2 specific thing here would be MoveObject, which is the name of our function (word) and the (“”,); are the grammar (the syntax for C/C++ like scripts) and Rock is a name of an object in the level editor and 10 is a specified value.

Good luck and remember to read and learn ALL script functions available, or just bookmark that page. ;)

Scripting with HPL2

A script file is a plain text file, with the same name as your map file. For example: my_test_level.map should have a my_test_level.hps text file in the same location. A script file can be edited using good old Notepad, if you do a lot of scripting it might be a good thing to read about Notepad