Welcome to AngelScript
AngelScript is a scripting language which allows applications to extend their functionality through external scripts.
To put it simple, it is a scripting language like Postal3Script, but it is very different from P3S, it has it's own compiler,
and it's way faster (also a lot more stable) in terms of code execution.
AngelScript is used as a layer for Postal3Script, which allows you to create complex code while still having P3S features.
You can read more about AngelScript here: http://angelcode.com/angelscript/
If you need a comprehensive list of all objects and functions, go back to the Index.
Why AngelScript?
Postal3Script has always been a very obscure scripting language, lack of documentation, weird syntax, and a very odd layout, which is unlike any other scripting languages out there.
As Catharsis Reborn extended the AI of all NPCs, so did the code too, but this where the cracks began to appear.
Spaghetti, ping-pong code writing from 'A' File, to 'B' File, ridiculously increasing lines where a single Block can go from 1 to 100, and it was very hard to go back and try to fix something wrong with the behavior you wrote, because it's not that very clear at first glance (especially when it's all over the place), to really use Postal3Script you have to learn the ins and outs, and even after a month you won't fully grasp it. (just remember that in 2016 the team was struggling with P3S!)
So there had to be a way of doing complex code without Postal3Script, at first (2020-2022) many of the complex behaviors
were hardcoded inside the source code because Postal3Script wasn't fully understood back then.
Slowly every hardcoded code were put into Postal3Script instead where it was obvious they must be there. (Inventory items for instance, due to scripting)
Creating dynamic events (such as the Wanted Reinforcements) without relying on modifying the maps and compiling back them everytime, was very, very questionable if it could be done with Postal3Script.
LUA was a 'Block' monstrosity like Postal3Script, and it wouldn't have been that easy to implement it in CR, so we went with AngelScript.
Postal3Script vs. AngelScript
Here are several facts about P3S:
- Hard to learn
- Only compiled when map restarts (can't force-recompile)
- Structure has a strict rule
- Compilation errors not always make sense
- Complex code might cause the AI to not work properly
- Very sensitive to spaces, tabs (heavily depends on how the function's compiler was programmed)
- Creativity isn't rewarded
- Complexity equals Spaghetti
- Extremely limited by functions in how you can interact with other entities
- Point of crashes are commonly very unclear
AngelScript has none of that, but this time spaghetti equals to programming skill.
AngelScript can access Postal3Script internal functions, like target, caller, memory, weapon, etc..
combine that with C++ syntax and you would get something like Postal3Script++.
On top of having access to almost all cruical Postal3Script functions, AngelScript also has access to normally inaccessible functions which you would only be able to use with the game's source code.
Here's an example below how one code looks in P3S and in AS. (behavior stays the same)
Note
The P3S code below only works for Catharsis Reborn, but you can still observe the amount of bloat it removes when converted to AngelScript.
Postal3Script:
IfAttr "cr_NoArms != 1 Block begin"
IfAttr "cr_NoRArm != 1 Block begin"
SetAttr "wpnattack 0"
IfAttr "Object:weapon != Object:NULL Block begin"
IfAttr "weapon.weapon_id != WPN_NONE Block begin"
IfAttr "weapon.weapon_type == WPN_MELEE SetAttr wpnattack 1"
IfAttr "weapon.weapon_type == WPN_LIMB SetAttr wpnattack 1"
Block end
Block end
IfAttr "wpnattack == 1 Block begin"
RemoveAttr "wpnattack"
Pattern pt_attack
Block end
RemoveAttr "wpnattack"
Block end
Block end
AngelScript:
if (self.GetAttr("cr_NoArms") != 1 && self.GetAttr("cr_NoRArm") != 1)
{
if (self.GetWeapon() != null)
{
int wpnType = self.GetWeapon().GetAttr("weapon_type");
if (wpnType == WPN_MELEE || wpnType == WPN_LIMB)
{
self.Pattern("pt_attack");
}
}
}
You can see how we greatly reduced the lines, and it's even clearer to understand and look at!
With AngelScript we can also get all the NPCs on the level, and check their manner, faction, state, health, etc.. all you can imagine, this is where Postal3Script stays in the dark in terms of usefulness, you can't fully interact with the level with P3S.