Page 1 of 1

npcParse.lua (Standardized NPC message parsing!)

Posted: Thu May 19, 2016 12:32 am
by Rixitic
rockythechao wrote:OH MY GOD YOU GUYS I MAY HAVE CAUSED THE SMBX Y2K HURRY WE HAVE TO DO SOMETHING ASAP THE FATE OF THE MULTIVERSE DEPENDS ON IT

*doesn't follow up on it for over a month*
(Context)

Er, uh... *ahem*
Yeah, sorry for the wait, everyone! Allow me to present:

npcParse.lua

Image

Download and documentation

This library loads data from both tables stored in the NPCs' message text and a JSON file in the level folder ("npcdata.json") and stores it in each NPC's pNPC data. You can even specify a message for the NPC to say once the data's been parsed!
This way multiple libraries can utilize the same NPC's message text, though libraries that currently read from the NPC message directly, such as my own cinematX and a few custom NPC ones, will have to be updated with an option to get the information from the pnpc data instead.

(Please note that the debug text shown in the above screenshot is not a feature of npcParse, but part of the test level's code that uses currently-unreleased features of textblox. I may implement it as a feature in a future update, however.)

Re: npcParse.lua (Standardized NPC message parsing!)

Posted: Thu May 19, 2016 12:36 am
by Alagirez
I'm still don't understand about the pNPC data or something, but this is a cool stuff. I will try this and see how it works.

Re: npcParse.lua (Standardized NPC message parsing!)

Posted: Thu May 19, 2016 12:53 am
by Rixitic
pNPC is an API that lets you grab persistent references to NPCs between frames and store additional data for those NPCs, like custom health or timers.

http://wohlsoft.ru/pgewiki/Pnpc.lua

All you need to do is add the script to LuaScriptsLib (assuming you don't already have it, I think it's packaged with new versions of LunaLua), then in the lua code:

Code: Select all

local pnpc = API.load("pnpc")

-- To get a pNPC reference from a regular NPC reference:
local pnpcReference = pnpc.wrap (npcReference)

-- For example:
function onTick ()
for key,val in pairs (NPC.get()) do
    -- Loop through every NPC and check their pnpc data
    local pnpcRef = pnpc.wrap (val)
    windowDebug (tostring(npncRef.data.example))
end

Re: npcParse.lua (Standardized NPC message parsing!)

Posted: Thu Jun 09, 2016 7:16 pm
by S1eth
I tried testing your program using your example code, and have the following problem.

I have one NPC in my level with the message text "{id="boss"}".

1. You forgot a "," after "THIS IS A REPLACEMENT MESSAGE, YO.", so at first, the code didn't work at all.

After I fixed the problem, the code added some things to the data table.
I wrote a recursive function to iterate over all fields/tables and write their ouput into a file.

Code: Select all

key: customlotus, val: table: 0x057e4f90
  key: bullets, val: 2
key: npcParse, val: table: 0x057e8dc8
  key: success, val: true
  key: msg, val: {id=boss}
The result is that it only copied the npcParse and "_ALL" values. My {id="boss"} had no extra tables created for it.

However, it did write key: msg, val: {id=boss} without the quotation marks around "boss" in the output, which leads me to believe that quotation marks don't work.

EDIT: it works

Code: Select all

key: customlotus, val: table: 0x057e53a8
  key: bullets, val: 999
key: cinematX, val: table: 0x057e52f0
  key: key, val: steve
  key: icon, val: 1
  key: id, val: boss
key: particles, val: table: 0x057e5250
  key: name, val: robert
key: newMsg, val: THIS IS A REPLACEMENT MESSAGE, YO.
key: npcParse, val: table: 0x057e8dc8
  key: success, val: true
  key: msg, val: {id='boss'}
It works. with {id='boss'}