groupings.lua (1.1)
Posted: 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:
Here's a look at the get function:
layer: The layer object to export data from
For example:
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:
The other way this function can be used:
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:
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:
Hopefully someone will find this useful. It sure made my life a lot easier: https://www.dropbox.com/s/k6it2texr4eeb ... s.lua?dl=0
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");
Code: Select all
groupings.get(layer);
For example:
Code: Select all
local groupings = API.load("groupings");
local defaultLayer = Layer(0); --the default layer
groupings.get(defaultLayer);
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},..
Code: Select all
local groupings = API.load("groupings");
local defaultLayer = Layer(0); --the default layer
function onStart()
local _, _, _, npcData = groupings.get(defaultLayer);
end
Here's a look at the print function:
Code: Select all
groupings.get(layer, clearLast);
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