Aseprite Script Lua "Try to index a nil value (global 'dlg')



我正在从头开始编写自己的Aseprite脚本来为我生成调色板,并希望使用下拉列表(组合框)来设置标记,以便以后在生成颜色时使用。(现在,写入控制台就足够了)

我很难弄清楚组合框是如何使用的,参考文档:https://github.com/aseprite/api/blob/main/api/dialog.md dialogcombobox

我的函数"是不可调用的(nil值)"如果在下拉列表之后编写,并且如果函数在它之前编写,我将获得"尝试索引nil值(全局'dlg')错误"。

所讨论的函数:

local function amountOfColorsChanged()
if dlg.data.amountOfColors == "7" then
print("Changed Amount of Colors to 7")
elseif dlg.data.amountOfColors == "9" then
print("Changed Amount of Colors to 9")
elseif dlg.data.amountOfColors == "11" then
print("Changed Amount of Colors to 11")
elseif dlg.data.amountOfColors == "13" then
print("Changed Amount of Colors to 13")
elseif dlg.data.amountOfColors == "15" then
print("Changed Amount of Colors to 15")
end
end

"combobox"在问题:

:combobox
{
id = "amountOfColors",
option = "15",
options =
{
"7",
"9",
"11",
"13",
"15"
},
onchange = amountOfColorsChanged()
}

如果我试图初始化变量以设置默认值

local dlg.data.amountOfColors = "15"

下面的"。" error附近的"意外符号"可能是因为我不能在变量中写入点。

因为我不知道如何从文档中读取/修改组合框的数据,我去寻找一个扩展,以类似的方式使用它们,我试图找到这个,这就是我如何得到我的方法:

https://github.com/not-surt/Limit-Colour-Component-Levels/blob/main/Limit%20Colour%20Component%20Levels.lua

(如果有问题的话,它的许可证允许我自由地复制和分发代码。然而,很明显,我不是)

这里是完整的脚本供参考。

-- Chaonic's Palette Helper
-- INITIALIZE!!!!
local dlg = Dialog
{ 
title = "Chaonic's Palette Helper"
}
-- Standard values when opening
if hasvalues ~= nil
then
hasvalues = true
local vmhueslider = 160
local vmsatslider = 40
local vmvalueslider = 35
local vmalphaslider = 255
end
function easeInQuad(self, x)
return x * x
end
function easeInSine(self, x)
return 1 - cos(nil, x * PI / 2)
end
function lerp()
end
-- TEST DELETE LATER
local C = app.fgColor
if(shadingColor ~= nil) then
C = shadingColor
end
-- COLOR AMOUNT CHANGED
local function amountOfColorsChanged()
if dlg.data.amountOfColors == "7" then
print("Changed Amount of Colors to 7")
elseif dlg.data.amountOfColors == "9" then
print("Changed Amount of Colors to 9")
elseif dlg.data.amountOfColors == "11" then
print("Changed Amount of Colors to 11")
elseif dlg.data.amountOfColors == "13" then
print("Changed Amount of Colors to 13")
elseif dlg.data.amountOfColors == "15" then
print("Changed Amount of Colors to 15")
end
end
-- COLOR VARIABLE STORAGE
local SH1 = colorShift(C, 0, 0.4, -0.6, -0.6)
local SH2 = colorShift(C, 0, 0.333, -0.5, -0.5)
local SH3 = colorShift(C, 0, 0.266, -0.4, -0.4)
local SH4 = colorShift(C, 0, 0.2, -0.3, -0.3)
local SH5 = colorShift(C, 0, 0.133, -0.2, -0.2)
local SH6 = colorShift(C, 0, 0.066, -0.1, -0.1)
local SH5 = colorShift(C, 0, 0, 0, 0)
local SH8 = colorShift(C, 0, 0.066, 0.1, 0.1)
local SH9 = colorShift(C, 0, 0.133, 0.2, 0.2)
local SH10 = colorShift(C, 0, 0.2, 0.3, 0.3)
local SH11 = colorShift(C, 0, 0.266, 0.4, 0.4)
local SH12 = colorShift(C, 0, 0.333, 0.5, 0.5)
local SH13 = colorShift(C, 0, 0.4, 0.6, 0.6)
-- DIALOG
dlg
:label
{
id=labelColorsLeft,
label = "Base Colors",
text= "Left"
}
:label
{
id=labelColorsMain,
text= "Main"
}
:label
{
id=labelColorsRight,
text= "Right"
}
:label
{
id=labelColorsClipboard,
text= "Clipboard"
}
:shades
{
id = "mainColors",
colors = {C, C, C, C}
}
:button
{
id = "buttonSetLeft",
text = "Set",
onclick = function()
end
}
:button
{
id = "buttonSetMain",
text = "Set",
onclick = function()
end
}
:button
{
id = "buttonSetRight",
text = "Set",
onclick = function()
end
}
:button
{
id = "buttonSetClipboard",
text = "Set",
onclick = function()
end
}
:label
{
id=labelColorsLeft,
label = "Amount of:",
text= "Colors"
}
:label
{
id=labelColorsLeft,
text= "Hues"
}
:combobox
{
id = "amountOfColors",
option = "15",
options =
{
"7",
"9",
"11",
"13",
"15"
},
onchange = amountOfColorsChanged()
}
:combobox
{
id = "amountOfHues",
option = "12",
options =
{
"4",
"6",
"8",
"12",
"18"
}
}
-- COLOR CONTROL
-- :separator
-- {
-- id = "separator",
-- }
-- :slider
-- {
-- id = "hueslider",
-- label = "Hue: ",
-- min = 0,
-- max = 360,
-- value = vmhueslider,
-- onchange = function()
-- end,
-- onrelease = function()
-- end
-- }
-- :slider
-- {
-- id = "satslider",
-- label = "Sat/Val: ",
-- min = 0,
-- max = 100,
-- value = vmsatslider,
-- onchange = function()
-- end,
-- onrelease = function()
-- end
-- }
-- :slider
-- {
-- id = "valueslider",
-- min = 0,
-- max = 100,
-- value = vmvalueslider,
-- onchange = function()
-- end,
-- onrelease = function()
-- end
-- }
-- :slider
-- {
-- id = "alphaeslider",
-- label = "Alpha: ",
-- min = 0,
-- max = 255,
-- value = vmalphaslider,
-- onchange = function()
-- end,
-- onrelease = function()
-- end
-- }
:label
{
id=huelabel,
label = "Interpolations: ",
text= "Hue"
}
:label
{
id=satlabel,
text= "Saturation"
}
:label
{
id=vallabel,
text= "Value"
}
:label
{
id=alphalabel,
text= "Alpha"
}
:combobox
{
id = "hueinterpolation",
option = "RGB",
options =
{
"Sine",
"Quad",
"Cubic",
"Circ",
"Linear",
"RGB"
}
}
:combobox
{
id = "satinterpolation",
option = "Quad",
options =
{
"Sine",
"Quad",
"Cubic",
"Circ",
"Linear",
"RGB"
}
}
:combobox
{
id = "valinterpolation",
option = "Quad",
options =
{
"Sine",
"Quad",
"Cubic",
"Circ",
"Linear",
"RGB"
}
}
:combobox
{
id = "alphainterpolation",
option = "Quad",
options =
{
"Sine",
"Quad",
"Cubic",
"Circ",
"Linear",
"RGB"
}
}
-- COLOR CONTROL END
:separator
{
id = "separator",
}
-- SHADE
:shades
{
id = "paletteShade",
label = "Shade",
colors = {C, C, C, C, C, C, C, C, C, C, C, C, C, C, C}
}
:button
{
id = "buttonShadeLine",
text = "Copy Line to Palette",
onclick = function()
end
}
:button
{
id = "buttonShadePalette",
text = "Generate whole Palette",
onclick = function()
end
}
-- SHADE END
-- SOFT SHADE
:shades
{
id = "paletteSoftShade",
label = "Soft Shade",
colors = {C, C, C, C, C, C, C, C, C, C, C, C, C, C, C}
}
:button
{
id = "buttonShadeLine",
text = "Copy Line to Palette",
onclick = function()
end
}
:button
{
id = "buttonShadePalette",
text = "Generate whole Palette",
onclick = function()
end
}
-- SOFT SHADE END
-- LIGHT
:shades
{
id = "paletteLight",
label = "Light",
colors = {C, C, C, C, C, C, C, C, C, C, C, C, C, C, C}
}
:button
{
id = "buttonShadeLine",
text = "Copy Line to Palette",
onclick = function()
end
}
:button
{
id = "buttonShadePalette",
text = "Generate whole Palette",
onclick = function()
end
}
-- LIGHT END
-- SOFT LIGHT
:shades
{
id = "paletteSoftLight",
label = "Soft Light",
colors = {C, C, C, C, C, C, C, C, C, C, C, C, C, C, C}
}
:button
{
id = "buttonShadeLine",
text = "Copy Line to Palette",
onclick = function()
end
}
:button
{
id = "buttonShadePalette",
text = "Generate whole Palette",
onclick = function()
end
}
-- SOFT LIGHT END
-- SATURATION
:shades
{
id = "paletteSaturation",
label = "Saturation",
colors = {C, C, C, C, C, C, C, C, C, C, C, C, C, C, C}
}
:button
{
id = "buttonShadeLine",
text = "Copy Line to Palette",
onclick = function()
end
}
:button
{
id = "buttonShadePalette",
text = "Generate whole Palette",
onclick = function()
end
}
-- SATURATION END
-- SOFT SATURATION
:shades
{
id = "paletteSoftSaturation",
label = "Soft Sat.",
colors = {C, C, C, C, C, C, C, C, C, C, C, C, C, C, C}
}
:button
{
id = "buttonShadeLine",
text = "Copy Line to Palette",
onclick = function()
end
}
:button
{
id = "buttonShadePalette",
text = "Generate whole Palette",
onclick = function()
end
}
-- SOFT SATURATION END
-- SOFT HUE
:shades
{
id = "paletteSoftHue",
label = "Soft Hue",
colors = {C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C}
}
:button
{
id = "buttonShadeLine",
text = "Copy Line to Palette",
onclick = function()
end
}
-- SOFT HUE END
-- HARD HUE
:shades
{
id = "paletteHardHue",
label = "Hard Hue",
colors = {C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C}
}
:button
{
id = "buttonShadeLine",
text = "Copy Line to Palette",
onclick = function()
end
}
-- HARD HUE END
:separator
{
id = "separator",
}
-- :button
-- {
-- id = "buttonPreset1",
-- label = "Presets: ",
-- text = "1",
-- onclick = function()
-- vmhueslider = 160
-- vmsatslider = 40
-- vmvalueslider = 35
-- vmalphaslider = 255
-- reload()
-- end
-- }
-- :button
-- {
-- id = "buttonPreset2",
-- text = "2",
-- onclick = function()
-- vmhueslider = 210
-- vmsatslider = 80
-- vmvalueslider = 80
-- vmalphaslider = 255
-- reload()
-- end
-- }
-- :button
-- {
-- id = "buttonPreset3",
-- text = "3",
-- onclick = function()
-- end
-- }
-- :button
-- {
-- id = "buttonPreset4",
-- text = "4",
-- onclick = function()
-- end
-- }
-- :button
-- {
-- id = "buttonPreset5",
-- text = "5",
-- onclick = function()
-- end
-- }
-- :button
-- {
-- id = "buttonPreset6",
-- text = "6",
-- onclick = function()
-- end
-- }
-- :newrow()
:button
{
id = "buttonGenerate",
text = "Generate",
onclick = function()
end
}
:button
{
id = "buttonReload",
text = "Reload",
onclick = function()
end
}
:button
{
id = "buttonCancel",
text = "Cancel",
onclick = function()
end
}
:show
{
wait = false
}

这是我的第一篇关于堆栈溢出的文章,所以我希望我做得对。非常感谢您的帮助!!

在再次查看文档以检查是否忘记提及某些内容时,我看到在https://github.com/aseprite/api/blob/main/api/dialog.md#dialogdata下需要首先初始化use。

只需将这些行添加到脚本中就可以工作了:

local data = dlg.data
dlg.data = data

相关内容

最新更新