npcParse.lua (Standardized NPC message parsing!)

This is the place for discussion and support for LunaLua and related modifications and libraries.
Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
User avatar
rixithechao
Pokey
Pokey
Posts: 218
Joined: Sat Dec 12, 2015 1:00 am
Current Project: A2XT2 and a few others

npcParse.lua (Standardized NPC message parsing!)

Postby rixithechao » Thu May 19, 2016 12:32 am

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.)
Last edited by rixithechao on Thu May 19, 2016 12:56 am, edited 2 times in total.
Some people just cannot avoid the ads on MediaFire, even with both common sense and popup blockers. It's always a good idea to provide an alternate download link with an ad-free file host such as Dropbox or Google Drive.

I do music, graphics, lua, birthdays, bachelor parties, bar mitzvahs, long walks on the beach, driving through the scenic countryside with my fabulous mutlicolored mustache flowing in the wind, living life on the edge and not playing by the rules, awkwardly standing in the corner of the room with my GBC during important company meetings, all my own stunts and baking cookies with criminally-high quantities of butter
Spoiler: show
Spinda wrote:gdi rocky
Waddle Derp wrote:rocky what the fuck
rockythechao wrote:gfdi me
Bread wrote:rocky
what did you do
ROCKY
Enjl wrote:you're walking a rocky road
Quantix wrote:jesus christ rocky
rockythechao wrote:the sin is indeed mine

User avatar
WerewolfGD
Wart
Wart
Posts: 3265
Joined: Tue Dec 02, 2014 2:28 am
Flair: Legalize Awooo!
Current Project: Howling
Chat Username: Alagirez
Contact:

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

Postby WerewolfGD » Thu May 19, 2016 12:36 am

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.
Yea... I'm back, but with different view.

Known also as Camacho or Harvey36Dice.
Also a furry

Image
Awooo!
If you want to talk with me, go here : Alagirez#2056

User avatar
rixithechao
Pokey
Pokey
Posts: 218
Joined: Sat Dec 12, 2015 1:00 am
Current Project: A2XT2 and a few others

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

Postby rixithechao » Thu May 19, 2016 12:53 am

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
Some people just cannot avoid the ads on MediaFire, even with both common sense and popup blockers. It's always a good idea to provide an alternate download link with an ad-free file host such as Dropbox or Google Drive.

I do music, graphics, lua, birthdays, bachelor parties, bar mitzvahs, long walks on the beach, driving through the scenic countryside with my fabulous mutlicolored mustache flowing in the wind, living life on the edge and not playing by the rules, awkwardly standing in the corner of the room with my GBC during important company meetings, all my own stunts and baking cookies with criminally-high quantities of butter
Spoiler: show
Spinda wrote:gdi rocky
Waddle Derp wrote:rocky what the fuck
rockythechao wrote:gfdi me
Bread wrote:rocky
what did you do
ROCKY
Enjl wrote:you're walking a rocky road
Quantix wrote:jesus christ rocky
rockythechao wrote:the sin is indeed mine

S1eth
Spiny
Spiny
Posts: 54
Joined: Sat Apr 23, 2016 10:44 am

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

Postby S1eth » Thu Jun 09, 2016 7:16 pm

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'}


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 4 guests