I figured I wanted to share some custom functions I've written recently. Amnesia/HPL2 is quite limited in what you can do, so I've used some workarounds to achieve what could've been done easily with external support. This might be a bit of an advanced topic for some of you, dunno.
This function is pre-defined in HPL2, and that's why you can use it. Anything listed on the Engine Scripts page is pre-defined. Everything else has to be created within the file in order to be used. This of course excludes the primitive syntax native to the scripting language.
So if you wanted to use a non-existant function like
then you'd need to create it. Now, this particular one isn't exactly game-changing, since the same effect can be achieved by using the VarInt function as 0/1, but it can be convenient for those who work with booleans more since you can directly input the variable without converting.
How do I use these functions?
Spoiler below!
It's simple enough. Each function depends on a snippet of code. Include the snippet for the function(s) you want to use within your .hps file. As long as it's present within the same file, you can call it like any of the pre-defined functions.
I will list the function itself as it is listed on the Engine Scripts page. I will give a brief explanation of the function and provide the script you need to include in order to use it.
Below I'll list whatever I've published so far below.
Boolean variables
Spoiler below!
These add to the already existing set for Int, Float and String.
Pretty self explanatory what they do; allow you to create and return a local or global true/false variable. These rely on there not already existing an Int variable with the name "bool_yourvar" (shouldn't really be an issue).
These are rather interesting and can be quite useful. They mimic the use of the array data type which is unsupported in HPL2. If you know how arrays work, these are self-explanatory.
These rely on there not existing string vars named "array_yourvar" and int vars named "array_yourvar_index". Can be changed of course.
string[] StringSplit(string &in asString, string &in asDelimiter) { int pause = 0; string[] flush = {}; SetLocalVarStringArray("_string_split", flush); Print("INFO: Splitting string '"+asString+"' with delimiter '"+asDelimiter+"'\n"); for(int i = 0; i <= asString.length(); i++) { string s = StringSub(asString, i, asDelimiter.length()); if(s == asDelimiter || i == asString.length()) { string split = StringSub(asString, pause, i-pause); AddLocalVarStringArray("_string_split", split); pause = i + asDelimiter.length(); } } return GetLocalVarStringArray("_string_split"); }
Float Decimal Limiter
Spoiler below!
This function will limit the amount of decimals a float value has. If you give it a value of 1.23456f and limit it to 3, it will return 1.234f. It does not round to nearest, it simply ignores the excess data.