Page 1 of 1

groupings.lua (1.1)

Posted: Wed Nov 23, 2016 8:56 pm
by PixelPest
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

Re: groupings.lua

Posted: Thu Nov 24, 2016 2:21 am
by Emral
Why not split them into .get and .print? Having to disable the printing every time sounds like a nuisance.

Re: groupings.lua

Posted: Thu Nov 24, 2016 6:49 am
by PixelPest
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

Re: groupings.lua (1.1)

Posted: Sat Nov 26, 2016 10:48 am
by PixelPest
Updated!

Implemented the suggestion Enjl made