----------
UPDATE #2: I have figured out the problem, but I still need help fixing it. See the replies to learn more.
----------
In my skin pack, illustro Gadgets, I am creating coloring options in the pack's settings skin. For each color, there are a few things: A box that shows the color, and when clicked will open RainRGB to allow the user to edit the color. There is a string meter that shows the color value itself (e.g. 250,250,250,200), and when clicked it pops up with a text field, allowing the user to directly edit the color value.
Last, but not least, there is a bar. This bar, when clicked, will change the color's alpha value to a specific percentage of the max, depending on where the bar is clicked (e.g. if you click the very rightmost point on the bar, it sets the alpha to 255, which is the max). This bar uses an LUA script I adopted from CircuitousTwo, which is also where I got the idea for the layout and looks of the coloring meters.
Or at least, this is what is SUPPOSED to happen. Whenever I click the bar, I get two very strange errors that I have puzzled over for several hours:
Code: Select all
Script: Settings.lua:\Files\Settings\Caleb\Rainmeter..."]:1: '<name>' expected near '\'
Script: Settings.luaattempt to call a table value
In an attempt to make sure there were no "ghost" characters (there is not a single backslash in the entire LUA script) I completely rewrote it from scratch, and cross-checked it to make absolutely 100% sure it would all work. Also, once you have tried clicking the alpha bar three times, Rainmeter will completely crash.
----------
UPDATE #1: I have discovered that the first time you try to click the alpha bar, it reports the errors I mentioned above. The SECOND time you do it, the error is slightly different:
Code: Select all
Script: Settings.lua:\Files\Settings\Caleb\Rainmeter..."]:1: '<name>' expected near '\'
Script: Settings.luaattempt to call a nil value
----------
Here is the link to the skin pack's GitHub repository, in which you can get the development version I am having this problem in (be sure to download the 'v0.8.0' branch, not the master branch.) The skin that uses the script is Settings.ini, under the appearance section. The script is in @Resources\Scripts\Settings.lua. For your convenience, I have copied the code of the script below, as well as the code for one of the color pickers.
Any and all help would be greatly appreciated.
Settings.lua code:
Code: Select all
isDbg = true
function Initialize()
hexChars = { [0]='0', [1]='1', [2]='2', [3]='3',
[4]='4', [5]='5', [6]='6', [7]='7',
[8]='8', [9]='9', [10]='a', [11]='b',
[12]='c', [13]='d', [14]='e', [15]='f' }
page = SKIN:GetVariable('pageName')
if page == 'appearance' then
colors = { SKIN:GetVariable('colorPrimary'),
SKIN:GetVariable('colorSecondary'),
SKIN:GetVariable('colorAccent'),
SKIN:GetVariable('colorDim') }
bars = { SKIN:GetMeter('ColorsPrimaryAlphaBar'),
SKIN:GetMeter('ColorsSecondaryAlphaBar'),
SKIN:GetMeter('ColorsAccentAlphaBar'),
SKIN:GetMeter('ColorsDimAlphaBar') }
maxBarW = SKIN:GetMeter('ColorsPrimaryAlphaBarBg'):GetW()
-- set the width of the alpha bars
for i=1,#colors do
tempW = math.floor(getStringAlphaPercent(colors[i]) * maxBarW)
SKIN:Bang('!SetOption', bars[i]:GetName(), 'W', tempW)
if isDbg == true then
print("IG: set width of '" .. tostring(bars[i]:GetName()) .. "'")
end
end
else
print("IG: wtf? invalid subpage id in settings skin!")
end
end
function Update()
end
-- Transparency manipulation functions
-- called from skin - changes alpha value on a color in the specified file
function changeAlpha(color, percent, filepath)
baseColor = SKIN:GetVariable(color)
alpha = math.floor(percent*0.01*255)
if (string.find(baseColor, ",") ~= nil) then
rgb = string.match(baseColor, "%d+,%d+,%d+")
newColor = rgb .. ',' .. alpha
else
rgb = string.sub(baseColor,1,6)
alpha = decToHex(alpha)
newColor = rgb .. alpha
end
SKIN:Bang('!WriteKeyValue','Variables',color, newColor, filepath)
end
-- intended to retrieve the alpha component of an RGBA or hex color and return as a percent 0.0 to 1.0
function getStringAlphaPercent(color)
local alpha
if (string.find(color, ",") ~= nil) then
rgbIt = string.gmatch(color,"%d+")
rgbTable = {}
for match in rgbIt do
table.insert(rgbTable, match)
end
if (#rgbTable < 4) then
alpha = 1
else
alpha = (rgbTable[4] / 255)
alpha = string.format("%.2f",alpha)
end
else
if (string.len(color)) > 6 then
alpha = hexToDec(string.sub(color,7,8))
alpha = (alpha / 255)
alpha = string.format("%.2f",alpha)
else
alpha = 1
end
end
return tonumber(alpha)
end
-- converts a hexadecimal string to a decimal number
function hexToDec(hexNum)
hexNum = string.lower(hexNum)
sum = 0
for i=1,#hexNum,1 do
sum = sum + (findHexChar(string.sub(hexNum,i,i)) * 16^(#hexNum-i))
end
return sum
end
-- converts decimal number to hexadecimal string
function decToHex(decNum)
local result = {}
while (decNum > 0) do
table.insert(result, 1, hexChars[math.fmod(decNum, 16)])
decNum = math.floor(decNum / 16)
end
return table.concat(result,'',1,#result)
end
-- linearly searches hexChar array for a given character and returns its index
function findHexChar(char)
for i=0,#hexChars do
if hexChars[i] == char then
return i
end
end
return -1
end
Code: Select all
[StyleColorsLabel]
FontSize=#fontSize2#
X=(#navMenuSeparatorX# + 10)
Y=23r
[StyleColorsBoxBg]
SolidColor=0,0,0,255
X=3r
Y=15r
W=24
H=24
[StyleColorsBox]
X=2r
Y=2r
W=20
H=20
ToolTipText="Edit this color using RainRGB"
[StyleColorsAlphaBarBg]
SolidColor=#colorDim#
X=26r
Y=0r
W=#colorAlphaBarBgWidth#
H=4
ToolTipText="Edit this color's alpha value (opacity)"
[StyleColorsAlphaBar]
SolidColor=#colorPrimary#
X=0r
Y=0r
H=4
[StyleColorsString]
FontSize=#fontSize2#
FontColor=#colorSecondary#
X=-2r
Y=8r
ToolTipText="Edit this color by typing an RGBA value"
; Primary Color
[ColorsPrimaryLabel]
Meter=String
MeterStyle=StyleText | StyleColorsLabel
Text="Primary Color"
[ColorsPrimaryBoxBg]
Meter=Image
MeterStyle=StyleColorsBoxBg
[ColorsPrimaryBox]
Meter=Image
MeterStyle=StyleColorsBox
LeftMouseUpAction=["#rainRgb#" "VarName=colorPrimary" "FileName=#commonSettingsPath#"]
MiddleMouseUpAction=[!WriteKeyValue Variables colorPrimary "#dColorPrimary#" "#commonSettingsPath#"][!RefreshGroup illustroGadgets]
SolidColor=#colorPrimary#
[ColorsPrimaryAlphaBarBg]
Meter=Image
MeterStyle=StyleColorsAlphaBarBg
LeftMouseUpAction=[!CommandMeasure MeasureSettingsScript "changeAlpha('colorPrimary',$MouseX:%$,#commonSettingsPath#)"][!RefreshGroup illustroGadgets]
[ColorsPrimaryAlphaBar]
Meter=Image
MeterStyle=StyleColorsAlphaBar
SolidColor=#colorPrimary#
W=1
[ColorsPrimaryString]
Meter=String
MeterStyle=StyleText | StyleColorsString
Text=#colorPrimary#
LeftMouseUpAction=[!CommandMeasure MeasureInputColorConfig "Executebatch 1"]
MiddleMouseUpAction=[!WriteKeyValue Variables colorPrimary "#dColorPrimary#" "#commonSettingsPath#"][!RefreshGroup illustroGadgets]