This article is an unfinished work in progress or contains transferred information that needs to be rewritten or reformatted to fit our standards. Please excuse the mess and do not mark for deletion.
It consists of a bytecode language that is stored in NPL files, each level then has a NERPFile parameter in Lego.cfg that tells it which script to use. This script is called once per game tick (25 times per second) by the game engine. It will run to completion on each execution, only stopping when the function named "Stop" is called or the end of the script is reached.
Each operation in the bytecode is a double word, where the top word designates the opcode and the lower word designates the operand. Of course this is stored in little endian format in the file itself.
The opcodes are as follows:
|0x0000||Constant||Load an integer constant, operand is the value|
|0x0001||Compares||Comparison operators, operand is the comparator function.|
|0x0002||Function||Calls a function, operand is the functions ID|
|0x0004||Label definition||Defines a label that can be jumped to, operand is just an ID number|
|0x0008||Goto||Jumps to a bytecode offset, operand is address to jump to|
Also involved are a couple of register named R0 to R7, the contents of which are saved between executions. There are also four timers, Timer0 to Timer3. The function of these is unknown at this time.
NRN files are the most easily readable form of NERPs script; they are uncompiled, unprocessed plain text. They were run through a C/C++ preprocessor in order to create the nrM files shipped with the game, so they use a combination of NERPs and C/C++ syntax (e.g.
// is used for comments, not
;). Most (but not all) NRN files in the game use macros defined in the nerpnrn.h header file to improve readability.
NRN files are not read by the game.
An nrM file is a plain-text version of a NERPs script. The nrM files in the game are NRN files that have been run through a C/C++ preprocessor (at DDI, the Visual Studio 6 C++ preprocessor was used); at this point, they would presumably be compiled into the NPL files the game actually reads, using DDI's own NERPs compiler.
nrM files are not read by the game.
NPL files are the compiled NERPs scripts that the game actually reads and executes.
All script from the nrM file is compiled into four bytes (two little-endian 16-bit words) for each scripted number, parameter/function, and symbol.
Numbers end in
00 00, Symbols end in
01 00, and Parameters end in
02 00. Certain Special Parameters also end in
04 00 and
08 00. The first 16-bit word in each pair indicates the number, or the number that a symbol or parameter has been given. For example, the number 4 is
04 00 00 00. Parameter #13, which is
0D 00 02 00. Symbol #5, which is the ">" symbol, is
05 00 01 00.
Putting them altogether
GetCrystalsCurrentlyStored > 4 becomes
0D 00 02 00 05 00 01 00 04 00 00 00.
- NERPs documentation
- NERPs example goal script
- NERPs setup guides:
- NERPs scripting with ogun's tool
- Ogun's NPL compiler/decompiler