Skip to content

Instantly share code, notes, and snippets.

@pingzing
Created July 26, 2025 20:28
Show Gist options
  • Select an option

  • Save pingzing/d6fae12aa41876738a97212d4f561990 to your computer and use it in GitHub Desktop.

Select an option

Save pingzing/d6fae12aa41876738a97212d4f561990 to your computer and use it in GitHub Desktop.
Aseprite Lua script to export for memory.undertale.com
local sprite = app.activeSprite
-- Check constraints
if sprite == nil then
app.alert("No Sprite...")
return
end
if sprite.colorMode ~= ColorMode.INDEXED then
app.alert("Sprite needs to be indexed")
return
end
local idxToColorName = {
[0] = '0',
[1] = '1',
[2] = 'r',
[3] = 'o',
[4] = 'y',
[5] = 'g',
[6] = 'b',
[7] = 't',
[8] = 'p',
[9] = '0'
};
local function getIndexData(img, w, h)
local res = ""
for y = 0, h - 1 do
for x = 0, w - 1 do
local px = img:getPixel(x, y)
local colorName = idxToColorName[px];
res = res .. string.format("%s", colorName)
end
-- res = res .. "\n"
end
return res
end
local function exportFrame(frm)
if frm == nil then frm = 1 end
local img = Image(sprite.spec)
img:drawSprite(sprite, frm)
io.write("Palette Indexed Picture\n")
io.write(getIndexData(img, sprite.width, sprite.height))
end
local dlg = Dialog()
dlg:file{
id = "exportFile",
label = "File",
title = "Undertale Memory Index Exporter",
open = false,
save = true,
filetypes = {"txt"}
}
dlg:check{
id = "onlyCurrentFrame",
text = "Export only current frame",
selected = true
}
dlg:button{id = "ok", text = "OK"}
dlg:button{id = "cancel", text = "Cancel"}
dlg:show()
local data = dlg.data
if data.ok then
local f = io.open(data.exportFile, "w")
io.output(f)
if data.onlyCurrentFrame then
exportFrame(app.activeFrame)
else
for i = 1, #sprite.frames do
io.write(string.format(";Frame %d\n", i))
exportFrame(i)
end
end
io.close(f)
end
@pingzing
Copy link
Copy Markdown
Author

Note that it assumes you have a palette set up in Aseprite with the following Index -> color mapping:
0 -> black
1 -> white
2- > red (ff0000)
3-> orange (fca600)
4 -> yellow (ffff00)
5 -> green (00c000)
6 -> blue (003cff)
7 -> light blue (42cff0)
8 -> purple (d535d9)
9 -> transparent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment