groupings.lua (1.1)

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?
PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

groupings.lua (1.1)

Postby PixelPest » Wed Nov 23, 2016 8:56 pm

Here's another API I wrote that may or may not be useful. This API uses one function to print the ID, x-position, and y-position of all blocks, NPCs, and BGOs from a specified layer to a file in table format, but also returns the tables as well as shown below.

Update 1.1: Now split up into a print function and a get function for better user-friendliness.

To use it, you can download the file from Dropbox and put it in your LuaScriptsLib folder. Then, load it as follows:

Code: Select all

local groupings = API.load("groupings");
Here's a look at the get function:

Code: Select all

groupings.get(layer);
layer: The layer object to export data from

For example:

Code: Select all

local groupings = API.load("groupings");

local defaultLayer = Layer(0); --the default layer

groupings.get(defaultLayer);
This would take all of the data from the default layer of the level and print it to the file. The file takes the form of the following:

Code: Select all

outputData Block: {ID, x, y}, {ID, x, y}, {ID, x, y},... BGO: {ID, x, y}, {ID, x, y}, {ID, x, y},... NPC: {ID, x, y}, {ID, x, y}, {ID, x, y},..
The other way this function can be used:

Code: Select all

local groupings = API.load("groupings");

local defaultLayer = Layer(0); --the default layer

function onStart()
	local _, _, _, npcData = groupings.get(defaultLayer);
end
This function also has four (4) return values: all of the data together in the form of {["Block"] = {}, ["BGO"] = {}, ["NPC"] = {}}, the block data (just one table with embedded tables of {ID, x, y}), as well as the third and fourth return values being for solely BGOs and solely NPCs.

Here's a look at the print function:

Code: Select all

groupings.get(layer, clearLast);
layer: The layer object to export data from
clearLast: The boolean value as to whether or not the previous data in the file should be erased (optional, default: true)

For example:

Code: Select all

local groupings = API.load("groupings");

local defaultLayer = Layer(0); --the default layer

function onStart()
	groupings.print(defaultLayer);
end
Hopefully someone will find this useful. It sure made my life a lot easier: https://www.dropbox.com/s/k6it2texr4eeb ... s.lua?dl=0
Last edited by PixelPest on Sat Nov 26, 2016 6:50 pm, edited 4 times in total.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9891
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: groupings.lua

Postby Emral » Thu Nov 24, 2016 2:21 am

Why not split them into .get and .print? Having to disable the printing every time sounds like a nuisance.

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: groupings.lua

Postby PixelPest » Thu Nov 24, 2016 6:49 am

Enjl wrote:Why not split them into .get and .print? Having to disable the printing every time sounds like a nuisance.
Good idea. I'll do that

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: groupings.lua (1.1)

Postby PixelPest » Sat Nov 26, 2016 10:48 am

Updated!

Implemented the suggestion Enjl made


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari