Advice for Scripting

From Frictional Wiki
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. The reason it gives you the final character is because, according to the compiler, the string never ends, and the code that is wrongfully included in that string is only considered as a string, rather than a piece of code. Thus, the compiler doesn't know that there are any problems until it discovers that the file ends before a closing quote is found. This kind of compiler error is usually accompanied by a message along the lines of Expected ".