npcParse.lua (Standardized NPC message parsing!)

This is the place for discussion and support for LunaLua and related modifications and libraries.

Moderator: Userbase Moderators

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?
Rixitic
Spike
Spike
Posts: 275
Joined: Sat Dec 12, 2015 1:00 am
Contact:

npcParse.lua (Standardized NPC message parsing!)

Postby Rixitic » 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 Rixitic on Thu May 19, 2016 12:56 am, edited 2 times in total.

Alagirez
Ludwig von Koopa
Ludwig von Koopa
Posts: 3624
Joined: Tue Dec 02, 2014 2:28 am
Flair: Legalize Awooo!
Pronouns: He/Him/That wolf
Contact:

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

Postby Alagirez » 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.

Rixitic
Spike
Spike
Posts: 275
Joined: Sat Dec 12, 2015 1:00 am
Contact:

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

Postby Rixitic » 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

S1eth
Bot
Bot
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 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari