Advice for Scripting

From Frictional Wiki
Revision as of 22:40, 13 August 2020 by Mudbill (talk | contribs) (Added a section for "reference" and "errors")
Jump to navigation Jump to search

This article is designed to give beginners the right mindset of approaching scripting in HPL. Remember that these are just tips intended to help you – you don't have to follow them, but they may teach you something useful.

Use references

If you are stuck trying to write a script, don't forget that you can always use Frictional's map scripts as a reference. They may help by giving concrete examples how you may use certain functions. This is particularly useful if you need to figure out how to set up a particular sequence of events that you remember from the game, for example how to set up a crowbar for use on a door along with effects, as is done in the Guest Room of Amnesia – The Dark Descent.

Listen to error messages

If you get a visible error message, perhaps as a pop-up in-game or as a crash message, they always provide some hints as to where the issue lies. If you see something like (123, 10) that means the compiler (which is responsible for changing your human-readable code into computer readable instructions) failed to process your script, and the numbers point to where in the script file the processing started to fail. The first number represents the line number in your file, and the second number represents the character on that line. The example above then means the problems starts on line 123 and character 10.

Sometimes the numbers you see will simply point to the last line and character in your file. This often means that there is a required character missing somewhere, like a double quote for a string. That is because, according to the compiler, the string may start at one point in the script but without the closing quote, it never ends, and the code that is wrongly included in that string is only considered as a string, rather than a piece of code. Thus, the compiler can't know exactly where the issue is. This kind of compiler error is usually combined with a message along the lines of Expected ".