Lua still baffles me...
Found this example lua script,
and my best guess was that (color) is were it gets the RGB code to convert.
But the script measure still reads out 0.
What am i missing here?
function ConvertToHex(color) -- Converts RGB colors to HEX
local hex = {}
for rgb in color:gmatch('%d+') do
table.insert(hex, ('%02X'):format(tonumber(rgb)))
end
return table.concat(hex)
end
StArL0rd84 wrote: ↑March 16th, 2019, 2:20 pm
Lua still baffles me...
Found this example lua script,
and my best guess was that (color) is were it gets the RGB code to convert.
But the script measure still reads out 0.
What am i missing here?
function ConvertToHex(color) -- Converts RGB colors to HEX
local hex = {}
for rgb in color:gmatch('%d+') do
table.insert(hex, ('%02X'):format(tonumber(rgb)))
end
return table.concat(hex)
end
That's not going to work, as you have two different approaches going on.
You have a Script measure that is attempting to execute the Update() function of a Lua script, while containing an option that holds the "color". In a Lua script with an Update() function, you could use SELF:() to read that color option from the Script measure, then take the action, which in and of itself is fine, and return the hex value to the Script measure to use elsewhere in your skin.
But you have a ConvertToHex() function in the Lua file, which is expecting to be directly called with a parameter of the "color" you want to return. That would be useful in Inline Lua, but as you have it now, that function is never called by anything.
I can get deeper into it if you want, but it would help to know how and where you want to use the hex value you are converting from rgb.
function ConvertToHex(color) -- Converts RGB colors to HEX
local hex = {}
for rgb in color:gmatch('%d+') do
table.insert(hex, ('%02X'):format(tonumber(rgb)))
end
return table.concat(hex)
end
1.jpg
Change the MyColor variable to 181,255,191 and you get:
You do not have the required permissions to view the files attached to this post.
There is just no advantage, and some disadvantage, to using this as a call to Update() in the Lua script with a SELF() option of the color. The disadvantage is that then you can only use it in one instance, since the color is hard-coded and can only deal with that one color. With Inline Lua, the same .lua file can be used to convert any color(s), on demand, as many places in the skin as you want.
jsmorley wrote: ↑March 16th, 2019, 2:29 pm
That's not going to work, as you have two different approaches going on.
You have a Script measure that is attempting to execute the Update() function of a Lua script, while containing an option that holds the "color". In a Lua script with an Update() function, you could use SELF:() to read that color option from the Script measure, then take the action, which in and of itself is fine, and return the hex value to the Script measure to use elsewhere in your skin.
But you have a ConvertToHex() function in the Lua file, which is expecting to be directly called with a parameter of the "color" you want to return. That would be useful in Inline Lua, but as you have it now, that function is never called by anything.
I can get deeper into it if you want, but it would help to know how and where you want to use the hex value you are converting from rgb.
I want to use the hex code in a image meters imagetint function.
The image meter is a icon for a menu which can have two colors depending on the state.
Just trying to condense:
ImageTint=(#MenuMode#=1?#ColorR#:#DefaultR#),(#MenuMode#=1?#ColorG#:#DefaultG#),(#MenuMode#=1?#ColorBlue#:#DefaultB#)
Into something like this:
ImageTint=(#MenuMode#=1?[ColorHex]:#DefaultRGB#)
function ConvertToHex(color) -- Converts RGB colors to HEX
local hex = {}
for rgb in color:gmatch('%d+') do
table.insert(hex, ('%02X'):format(tonumber(rgb)))
end
return table.concat(hex)
end
1.jpg
Change the MyColor variable to 181,255,191 and you get:
I suppose jsmorley will disagree pretty much this, but this has been discussed before and I've suggested a solution which didn't use lua script for this conversion. Here it is, if you're interested: https://forum.rainmeter.net/viewtopic.php?f=119&t=26950
balala wrote: ↑March 16th, 2019, 2:56 pm
I suppose jsmorley will disagree pretty much with this, but this has been discussed before and I've suggested a solution which didn't use lua script for this conversion. Here it is, if you're interested: https://forum.rainmeter.net/viewtopic.php?f=119&t=26950
No, I don't disagree. Simply converting RGB to HEX probably doesn't require Lua.
Again though, I like the fact that a simple function in Lua can be used a hundred places in your skin without having to duplicate any effort or create a bunch of extra measures.