NpcParse.lua

Download

npcParse.lua is a library designed to provide a standardized method of storing shared data in an NPC's message text.

Installation
Install pnpc.lua by following the instructions on that library's page, then place the file npcParse.lua into the LuaScriptsLib folder.

Basic Setup
To enable the npcParse library for a specific level, add this line to lunadll.lua:

It is also recommended to create a JSON file named npcdata.json in the level's resource folder.

How it Works
At runtime, npcParse will read lua tables stored in NPCs' message text and copy their information to the data tables of the respective pNPC references so that libraries can access them through ''.data. , .data. . , .data. . .'' and so on. NPCs without correctly-formatted tables will be ignored. npcParse utilizes the following (optional) keys for additional functionality:

npcParse also uses two special keys in npcdata.json: if a section labeled "_ALL" is defined, every NPC will be given the data in that section. If a section labeled "_ID" is defined, every NPC with a valid id key will receive that data. Data defined in user-named keys overrides the same properties in "_ID", and data in "_ID" overrides data in "_ALL".

Example
NPCs with the first sample message will display the message "THIS IS A REPLACEMENT MESSAGE, YO." when spoken to and have all of the data in the "boss" table of the JSON file (e.g. .data.particles.name, etc.) NPCs with the second sample message cannot be spoken to (because newMsg is not defined) and will have the data in the "minion" table of the JSON file (.data.npcGfx, etc.) as well as the extra property quack (.data.quack). Every single NPC will have .data.customlotus.bullets, but NPCs with the boss ID will have a value of 999 stored there whereas every other NPC will have 2 instead.

For helper library devs
Developers of LunaLua libraries that utilize the NPC message text (such as customlotus and new NPCs) are strongly encouraged to design their APIs to load the necessary data from ''.data. ''; this ensures standardized compatibility between such libraries through npcParse.

Strings
It's generally safer to store newMsg strings and other complex string values in the npcdata.json file instead of directly in the message table as the SMBX editor may convert double quotation marks in NPC text into apostrophes. A possible alternative for the newMsg strings would be to give each applicable NPC a unique replacement string and check for that as a secondary id within the onMessageBox event, like so: